【发布时间】:2021-10-10 20:12:34
【问题描述】:
我已经为敌人编写了代码,它会左右移动并停在窗台上,但由于某种原因,敌人会消失得无影无踪,但当我要去的时候,敌人仍然可以击中你靠近敌人所在的位置。
这是我为 Enemy AI 编写的代码:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PatrollingEnemy : MonoBehaviour
{
public float speed;
private bool movingRight = true;
public Transform groundDetection; //detects the ground if it is there...
// Update is called once per frame
void Update()
{
transform.Translate(Vector2.right * speed * Time.deltaTime);
RaycastHit2D groundInfo = Physics2D.Raycast(groundDetection.position, Vector2.down, 2f);
if (groundInfo.collider == false)
{
if(movingRight == true)
{
transform.eulerAngles = new Vector2(0, -200);
movingRight = false;
}
else
{
transform.eulerAngles = new Vector2(0, 0);
movingRight = true;
}
}
}
}
如果您想了解它如何使用此代码,请点击以下链接:Link for Bug
【问题讨论】:
标签: c# unity3d game-development