我正在尝试为我的游戏制作一个碰撞脚本,当玩家碰到障碍物时,移动脚本将被禁用。因此,我试图为碰撞制作一个单独的脚本,但当玩家碰到障碍物时,移动脚本仍然处于活动状态。因此,我试图修改原始移动脚本,但随后我得到了一堆错误。
下面是我使用的代码:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MovementAndJump : MonoBehaviour
{
public Rigidbody rb;
float forwardForce = 500f;
float jumpForce = 2000f;
public BoxCollider collision;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
rb.AddForce(0, 0, forwardForce * Time.deltaTime);
if (Input.GetKey("w") && collisionInfo.collider.tag = "Ground")
{
rb.AddForce(0, jumpForce * Time.deltaTime, 0);
}
}
void OnCollisionEnter (Collision collisionInfo)
{
if (collisionInfo.collider.Tag == "Obstacle")
{
MovementAndJump.Enabled = false;
}
}
}
以下是我得到的错误:
- “命名空间''已包含'MovementAndJump'的定义
- “类型'MovementAndJump'已经定义了一个名为'Start'的具有相同参数类型的成员”
- “Type 'MovementAndJump' already defines a member called 'Update' with the same parameter types”有人知道解决这个问题的方法吗?
1条答案
按热度按时间oxalkeyp1#
将
MovementAndJump.Enabled = false
更改为this.Enabled = false
应该能修好