Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class randomMovement : MonoBehaviour {
- public float speed = 20f;
- private Vector3 direction;
- // Use this for initialization
- void Start () {
- direction = new Vector3(Random.Range(-1.0f, 1.0f), 0.0f, Random.Range(-1.0f, 1.0f));
- InvokeRepeating("changeDirection", 0.1f, 2.0f);
- }
- // Update is called once per frame
- void Update () {
- transform.position += direction * SPEED * Time.deltaTime;
- }
- void changeDirection() {
- direction = new Vector3(Random.Range(-1.0f, 1.0f), 0.0f, Random.Range(-1.0f, 1.0f));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement