transform.right 物体沿x轴方向移动
transform.up 物体沿y轴方向移动
transform.forward 物体沿z轴方向移动
使飞机1的头部指向指向飞机2
、
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Myjet : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
//Debug.Log("y轴向量:" + transform.up);
//Debug.Log("x轴向量:" + transform.right);
//Debug.Log("y轴向量:"+transform.forward);
Vector3 face = this.transform.up;
//找到小球目标
GameObject target = GameObject.Find("飞机2");
Vector3 direction = target.transform.position - this.transform.position;
//得到方向向量
//求旋转夹角
float angle = Vector3.SignedAngle(face, direction, Vector3.forward);
this.transform.Rotate(0, 0, angle);//旋转
}
// Update is called once per frame
void Update()
{
}
}