int pointIndex=0;//表示下标
Gamectrl._Instance.pathArr;//表示一个点位数组
//向目标点移动
transform.localPosition = Vector3.MoveTowards(transform.localPosition, Gamectrl._Instance.pathArr[pointIndex].localPosition, Time.deltaTime * playerMoveSpeed +chongciSpeed);
//判断豆豆与点的距离
if (Vector2.Distance(transform.localPosition, Gamectrl._Instance.pathArr[pointIndex].localPosition) < 1f)
{
//下一个点
pointIndex++;
dir = Gamectrl._Instance.pathArr[pointIndex].localPosition - transform.localPosition;
//Debug.Log(dir+" "+Vector3.Dot(transform.forward, dir));
//使用点乘 差乘
if (Vector3.Dot(transform.up,dir)>10)
{
//Debug.Log("上");
/**
PlayerChange(0);
fire.transform.SetParent(playerArr[0].transform);
fire.transform.localPosition= new Vector3(-0.3f, 0, 0);
fire.transform.localRotation = Quaternion.Euler(0, 0, -180);
fire.transform.localScale = Vector3.one;
moveType = MoveType.Up;
*/
}
else if (Vector3.Dot(transform.up, dir) < -10)
{
//Debug.Log("下");
/**
PlayerChange(1);
fire.transform.SetParent(playerArr[1].transform);
fire.transform.localPosition = new Vector3(-0.3f, 0, 0);
fire.transform.localRotation = Quaternion.Euler(0, 0, 180);
fire.transform.localScale = Vector3.one;
moveType = MoveType.Down;
*/
}
else if(Vector3.Cross(transform.forward, dir).y > 10)
{
//Debug.Log("右");
/**
PlayerChange(3);
fire.transform.SetParent(playerArr[3].transform);
fire.transform.localPosition = new Vector3(0.3f, 0, 0);
fire.transform.localRotation = Quaternion.Euler(0, 0, 0);
fire.transform.localScale = Vector3.one;
moveType = MoveType.Right;
*/
}
else if (Vector3.Cross(transform.forward, dir).y < -10)
{
//Debug.Log("左");
/**
PlayerChange(2);
fire.transform.SetParent(playerArr[2].transform);
fire.transform.localPosition = new Vector3(-0.3f, 0, 0);
fire.transform.localRotation = Quaternion.Euler(180, 0, 180);
fire.transform.localScale = Vector3.one;
moveType = MoveType.Left;
*/
}
}
Unity判断目标在哪个方向
最新推荐文章于 2024-03-28 15:22:26 发布