Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- [RequireComponent(typeof(Rigidbody))]
- public class GhostMover : MonoBehaviour {
- public Vector3 nextPlaceToGo;
- public float timerSeconds = 1;
- private float timePassed;
- void Start() {
- GetComponent<Rigidbody> ().useGravity = false;
- }
- void FixedUpdate () {
- timePassed += Time.deltaTime;
- if (timePassed >= timerSeconds) {
- nextPlaceToGo = transform.position + Random.onUnitSphere;
- timePassed = 0;
- }
- Vector3 actualDirection = nextPlaceToGo - transform.position;
- GetComponent<Rigidbody> ().velocity = actualDirection.normalized;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement