Advertisement
JonneOpettaja

Untitled

Dec 15th, 2017
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class randomMovement : MonoBehaviour {
  6.  
  7. public float speed = 20f;
  8. private Vector3 direction;
  9.  
  10. // Use this for initialization
  11. void Start () {
  12. direction = new Vector3(Random.Range(-1.0f, 1.0f), 0.0f, Random.Range(-1.0f, 1.0f));
  13. InvokeRepeating("changeDirection", 0.1f, 2.0f);
  14. }
  15.  
  16. // Update is called once per frame
  17. void Update () {
  18. transform.position += direction * SPEED * Time.deltaTime;
  19. }
  20.  
  21. void changeDirection() {
  22. direction = new Vector3(Random.Range(-1.0f, 1.0f), 0.0f, Random.Range(-1.0f, 1.0f));
  23. }
  24.  
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement