这是附加到对象上的敌人脚本。我真的不知道为什么它不起作用,但是除了刚体之外,我传递的其他值也起作用。也没有显示警告或错误。
public class Enemy : MonoBehaviour {
private EnemyMovement movement;
private Rigidbody2D rBody;
public GameObject ball;
void Start () {
rBody = GetComponent<Rigidbody2D> ();
movement = new EnemyMovement ();
movement.SetJump(false);
movement.SetWalkDur (Random.Range (0, EnemyMovement.MAX_WALK_DURATION));
movement.SetSwapDirDur (Random.Range (0,
EnemyMovement.MAX_SWAP_DIRECTION_DURATION));
}
void FixedUpdate () {
if (movement.IsJump()) {
movement.Jump (ball, rBody, transform);
} else {
movement.Move (rBody, transform);
}
}
这是EnemyMovement类,我在其中传递了刚体的值。
public class EnemyMovement{
public EnemyMovement(){}
public void Move(Rigidbody2D rBody, Transform transform){
walkDur -= Time.deltaTime;
swapDirDur -= Time.deltaTime;
if(swapDirDur <= 0)
swapDirDur = Random.Range (0, MAX_SWAP_DIRECTION_DURATION);
if (walkDur <= 0) {
jumpStatus = true;
walkDur = Random.Range (0, MAX_WALK_DURATION);
}
switch (side) {
case "Top":
Movement ("Horizontal", rBody, transform);
break;
case "Bottom":
Movement ("Horizontal", rBody, transform);
break;
case "Right":
Movement ("Vertical", rBody, transform);
break;
case "Left":
Movement ("Vertical", rBody, transform);
break;
}
}
}
我真的找不到解决我问题的方法。我希望这里有人可以帮助我。