Unity 学习笔记汇总
Debug.DrawRay官方API使用文档
1. 前台
2. 代码
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class NewBehaviourScript : MonoBehaviour
{
// Start is called before the first frame update
public Ray myRay;
public GameObject cube, sphere, cube2;
float speed = 2f;
RaycastHit myHit;
void Start()
{
}
// Update is called once per frame
void Update()
{
Vector3 moveDir = sphere.transform.position - cube.transform.position;
myRay = new Ray(cube.transform.position, moveDir);
//
Debug.DrawRay(myRay.origin, myRay.direction * 20, Color.red);
Debug.DrawRay(cube.transform.position, myRay.direction * 20, Color.red);
//Debug.DrawRay(myRay.GetPoint(2f), myRay.direction, Color.red);
//cube.transform.Translate(moveDir * Time.deltaTime * speed);
//cube2.transform.Translate(moveDir * Time.deltaTime * speed);
}
}
3. 结果
运行后点击Scene,会看到有一条射线