Advertisement
Guest User

bar with cursor code

a guest
Jul 22nd, 2017
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.49 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class seiya_walk : MonoBehaviour {
  5.  
  6.     public GameObject bar;
  7.     public GameObject cursor;
  8.     public bool inSkillBar;
  9.  
  10.     // Use this for initialization
  11.     void Start () {
  12.    
  13.     }
  14.  
  15.     // Update is called once per frame
  16.     void Update()
  17.     {
  18.         if (Input.GetKeyDown(KeyCode.S))
  19.         {
  20.             if (gameObject.GetComponent<Animator>().GetInteger("walk") == 1) { print(1); }
  21.             gameObject.GetComponent<Animator>().SetInteger("walk", gameObject.GetComponent<Animator>().GetInteger("walk") == 1 ? 2 : 1);
  22.         }
  23.         if (Input.GetKeyDown(KeyCode.T))
  24.         {
  25.             inSkillBar = true;
  26.             StartCoroutine(BarMove());
  27.         }
  28.     }
  29.     IEnumerator BarMove()
  30.     {
  31.         bar.SetActive(true);
  32.         cursor.SetActive(true);
  33.         cursor.transform.position = new Vector3(bar.transform.position.x, bar.transform.position.y - 0.54f, 1f);
  34.         Vector3 moveWhere = new Vector3(0f, 0.045f, 0f);
  35.         while (inSkillBar)
  36.         {
  37.             yield return new WaitForSeconds(0.01f);
  38.             cursor.transform.position += moveWhere;
  39.             if(cursor.transform.localPosition.y >= 0.129f)
  40.             {
  41.                 moveWhere = -moveWhere;
  42.             }
  43.             else if (cursor.transform.localPosition.y <= -0.179f)
  44.             {
  45.                 moveWhere = -moveWhere;
  46.             }
  47.             if(moveWhere == new Vector3(0f, -0.1f, 0f)) { print("truth"); }
  48.         }
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement