1234567891011121314151617181920212223242526272829303132333435363738 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class NewBehaviourScript : MonoBehaviour
- {
- Transform cube;
- Vector3 p1;
- Vector3 p2;
- // Start is called before the first frame update
- void Start()
- {
- Debug.Log("²Ý˵£º¡°Å£±Æ¡±");
- GameObject cube = GameObject.Find("Cube123");
- p1 = cube.transform.position;
- p2 = this.gameObject.transform.position;
- Application.targetFrameRate = 60;
- this.transform.LookAt(cube.transform);
- }
- // Update is called once per frame
- void Update()
- {
-
- if ((p2 - p1).magnitude > 2f)
- {
- p2 = this.transform.position;
- this.transform.Translate(0, 0, 1 * Time.deltaTime, Space.Self);
- } else
- {
- this.transform.position += new Vector3(0, 0, 0.01f);
- this.transform.LookAt(cube.transform);
- }
- }
- }
|