Advertisement
Guest User

Untitled

a guest
Apr 30th, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.26 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class girlMov : MonoBehaviour
  6. {
  7.  
  8.     public float moveSpeed;
  9.     private Rigidbody2D myRigidbody2D;
  10.     public bool isWalking;
  11.     public float walkTime;
  12.     public float waitTime;
  13.     private float walkCounter;
  14.     private float waitCounter;
  15.     private int walkDirection;
  16.     // Use this for initialization
  17.     void Start ()
  18.     {
  19.         myRigidbody2D = GetComponent<Rigidbody2D>();
  20.         waitCounter = waitTime;
  21.         walkCounter = walkTime;
  22.         ChooseDirection();
  23.     }
  24.    
  25.     // Update is called once per frame
  26.     void Update () {
  27.         if (isWalking)
  28.         {
  29.             walkCounter -= Time.deltaTime;
  30.             switch (walkDirection)
  31.             {
  32.                 case 0:
  33.                     myRigidbody2D.velocity = new Vector2(0, moveSpeed);
  34.                     break;
  35.                 case 1:
  36.                     myRigidbody2D.velocity = new Vector2(moveSpeed, moveSpeed);
  37.                     break;
  38.                 case 2:
  39.                     myRigidbody2D.velocity = new Vector2(moveSpeed, 0);
  40.                     break;
  41.                 case 3:
  42.                     myRigidbody2D.velocity = new Vector2(moveSpeed, -moveSpeed);
  43.                     break;
  44.                 case 4:
  45.                     myRigidbody2D.velocity = new Vector2(0, -moveSpeed);
  46.                     break;
  47.                 case 5:
  48.                     myRigidbody2D.velocity = new Vector2(-moveSpeed, -moveSpeed);
  49.                     break;
  50.                 case 6:
  51.                     myRigidbody2D.velocity = new Vector2(-moveSpeed, 0);
  52.                     break;
  53.                 case 7:
  54.                     myRigidbody2D.velocity = new Vector2(-moveSpeed, moveSpeed);
  55.                     break;
  56.             }
  57.             if (walkCounter < 0)
  58.             {
  59.                 isWalking = false;
  60.                 waitCounter = waitTime;
  61.             }
  62.         }
  63.         else
  64.         {
  65.             waitCounter -= Time.deltaTime;
  66.             myRigidbody2D.velocity = Vector2.zero;
  67.             if (waitCounter < 0)
  68.             {
  69.                 ChooseDirection();
  70.             }
  71.         }
  72.     }
  73.  
  74.     public void ChooseDirection()
  75.     {
  76.         walkDirection = Random.Range(0, 8);
  77.         isWalking = true;
  78.         walkCounter = walkTime;
  79.     }
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement