NewBehaviourScript.cs 929 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class NewBehaviourScript : MonoBehaviour
  5. {
  6. Transform cube;
  7. Vector3 p1;
  8. Vector3 p2;
  9. // Start is called before the first frame update
  10. void Start()
  11. {
  12. Debug.Log("²Ý˵£º¡°Å£±Æ¡±");
  13. GameObject cube = GameObject.Find("Cube123");
  14. p1 = cube.transform.position;
  15. p2 = this.gameObject.transform.position;
  16. Application.targetFrameRate = 60;
  17. this.transform.LookAt(cube.transform);
  18. }
  19. // Update is called once per frame
  20. void Update()
  21. {
  22. if ((p2 - p1).magnitude > 2f)
  23. {
  24. p2 = this.transform.position;
  25. this.transform.Translate(0, 0, 1 * Time.deltaTime, Space.Self);
  26. } else
  27. {
  28. this.transform.position += new Vector3(0, 0, 0.01f);
  29. this.transform.LookAt(cube.transform);
  30. }
  31. }
  32. }