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 girlMov : MonoBehaviour
- {
- public float moveSpeed;
- private Rigidbody2D myRigidbody2D;
- public bool isWalking;
- public float walkTime;
- public float waitTime;
- private float walkCounter;
- private float waitCounter;
- private int walkDirection;
- // Use this for initialization
- void Start ()
- {
- myRigidbody2D = GetComponent<Rigidbody2D>();
- waitCounter = waitTime;
- walkCounter = walkTime;
- ChooseDirection();
- }
- // Update is called once per frame
- void Update () {
- if (isWalking)
- {
- walkCounter -= Time.deltaTime;
- switch (walkDirection)
- {
- case 0:
- myRigidbody2D.velocity = new Vector2(0, moveSpeed);
- break;
- case 1:
- myRigidbody2D.velocity = new Vector2(moveSpeed, moveSpeed);
- break;
- case 2:
- myRigidbody2D.velocity = new Vector2(moveSpeed, 0);
- break;
- case 3:
- myRigidbody2D.velocity = new Vector2(moveSpeed, -moveSpeed);
- break;
- case 4:
- myRigidbody2D.velocity = new Vector2(0, -moveSpeed);
- break;
- case 5:
- myRigidbody2D.velocity = new Vector2(-moveSpeed, -moveSpeed);
- break;
- case 6:
- myRigidbody2D.velocity = new Vector2(-moveSpeed, 0);
- break;
- case 7:
- myRigidbody2D.velocity = new Vector2(-moveSpeed, moveSpeed);
- break;
- }
- if (walkCounter < 0)
- {
- isWalking = false;
- waitCounter = waitTime;
- }
- }
- else
- {
- waitCounter -= Time.deltaTime;
- myRigidbody2D.velocity = Vector2.zero;
- if (waitCounter < 0)
- {
- ChooseDirection();
- }
- }
- }
- public void ChooseDirection()
- {
- walkDirection = Random.Range(0, 8);
- isWalking = true;
- walkCounter = walkTime;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement