Advertisement
mvaganov

Untitled

Feb 19th, 2017
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. [RequireComponent(typeof(Rigidbody))]
  6. public class GhostMover : MonoBehaviour {
  7.  
  8. public Vector3 nextPlaceToGo;
  9. public float timerSeconds = 1;
  10. private float timePassed;
  11.  
  12. void Start() {
  13. GetComponent<Rigidbody> ().useGravity = false;
  14. }
  15.  
  16. void FixedUpdate () {
  17. timePassed += Time.deltaTime;
  18. if (timePassed >= timerSeconds) {
  19. nextPlaceToGo = transform.position + Random.onUnitSphere;
  20. timePassed = 0;
  21. }
  22. Vector3 actualDirection = nextPlaceToGo - transform.position;
  23. GetComponent<Rigidbody> ().velocity = actualDirection.normalized;
  24. }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement