Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class TaoistMovement : MonoBehaviour
- {
- //Animator anim
- bool left direction;
- bool right direction;
- bool front direction;
- bool back direction;
- // Use this for initialization
- void Start()
- {
- }
- void Update()
- {
- float MoveSpeed = 4.5f;
- string charactersname = "taoistmoveobject";
- string charactername = "taoist";
- //change the string to my parameter
- string charactersfrontwalk = "FrontWalk";
- string charactersbackwalk = "BackWalk";
- string charactersleftwalk = "LeftWalk";
- string charactersrightwalk = "RightWalk";
- string charactersfrontidle = "FrontIdle";
- string charactersbackidle = "BackIdle";
- string charactersrightidle = "RightIdle";
- string charactersleftidle = "LeftIdle";
- GameObject characters = GameObject.Find(charactersname);
- GameObject theanim = GameObject.Find(charactername);
- //something
- character.transform.localPosition = new Vector3(character.transform.localPosition.x, character.transform.localPosition.y + 0.05f * MoveSpeed, character.transform.localPosition.z);
- character.transform.localPosition = new Vector3(character.transform.localPosition.x - 0.05f * MoveSpeed, character.transform.localPosition.y, character.transform.localPosition.z);
- if (!Input.GetKey("up") && !Input.GetKey("down") && !Input.GetKey("left") && !Input.GetKey("right"))
- {
- if (FrontDirection == true)
- {
- theanim.GetComponent<Animator>().SetBool(charactersfrontwalk, false);
- theanim.GetComponent<Animator>().SetBool(charactersbackwalk, false);
- theanim.GetComponent<Animator>().SetBool(charactersleftwalk, false);
- theanim.GetComponent<Animator>().SetBool(charactersrightwalk, false);
- theanim.GetComponent<Animator>().SetBool(charactersfrontidle, true);
- theanim.GetComponent<Animator>().SetBool(charactersbackidle, false);
- theanim.GetComponent<Animator>().SetBool(charactersrightidle, false);
- theanim.GetComponent<Animator>().SetBool(charactersleftidle, false);
- }
- if (BackDirection == true)
- {
- theanim.GetComponent<Animator>().SetBool(charactersfrontwalk, false);
- theanim.GetComponent<Animator>().SetBool(charactersbackwalk, false);
- theanim.GetComponent<Animator>().SetBool(charactersleftwalk, false);
- theanim.GetComponent<Animator>().SetBool(charactersrightwalk, false);
- theanim.GetComponent<Animator>().SetBool(charactersfrontidle, false);
- theanim.GetComponent<Animator>().SetBool(charactersbackidle, true);
- theanim.GetComponent<Animator>().SetBool(charactersrightidle, false);
- theanim.GetComponent<Animator>().SetBool(charactersleftidle, false);
- }
- if (LeftDirection == true)
- {
- theanim.GetComponent<Animator>().SetBool(charactersfrontwalk, false);
- theanim.GetComponent<Animator>().SetBool(charactersbackwalk, false);
- theanim.GetComponent<Animator>().SetBool(charactersleftwalk, false);
- theanim.GetComponent<Animator>().SetBool(charactersrightwalk, false);
- theanim.GetComponent<Animator>().SetBool(charactersfrontidle, false);
- theanim.GetComponent<Animator>().SetBool(charactersbackidle, false);
- theanim.GetComponent<Animator>().SetBool(charactersrightidle, false);
- theanim.GetComponent<Animator>().SetBool(charactersleftidle, true);
- }
- if (RightDirection == true)
- {
- theanim.GetComponent<Animator>().SetBool(charactersfrontwalk, false);
- theanim.GetComponent<Animator>().SetBool(charactersbackwalk, false);
- theanim.GetComponent<Animator>().SetBool(charactersleftwalk, false);
- theanim.GetComponent<Animator>().SetBool(charactersrightwalk, false);
- theanim.GetComponent<Animator>().SetBool(charactersfrontidle, false);
- theanim.GetComponent<Animator>().SetBool(charactersbackidle, false);
- theanim.GetComponent<Animator>().SetBool(charactersrightidle, true);
- theanim.GetComponent<Animator>().SetBool(charactersleftidle, false);
- }
- }
- if (Input.GetKey("up") || Input.GetKey("down") || Input.GetKey("left") || Input.GetKey("right"))
- {
- if (Input.GetKey("up") && !(Input.GetKey("down") || Input.GetKey("left") || Input.GetKey("right")))
- {
- theanim.GetComponent<Animator>().SetBool(charactersfrontwalk, false);
- theanim.GetComponent<Animator>().SetBool(charactersbackwalk, true);
- theanim.GetComponent<Animator>().SetBool(charactersleftwalk, false);
- theanim.GetComponent<Animator>().SetBool(charactersrightwalk, false);
- theanim.GetComponent<Animator>().SetBool(charactersfrontidle, false);
- theanim.GetComponent<Animator>().SetBool(charactersbackidle, false);
- theanim.GetComponent<Animator>().SetBool(charactersrightidle, false);
- theanim.GetComponent<Animator>().SetBool(charactersleftidle, false);
- LeftDirection = false;
- RightDirection = false;
- BackDirection = true;
- FrontDirection = false;
- characters.transform.localPosition = new Vector3(characters.transform.localPosition.x, characters.transform.localPosition.y, characters.transform.localPosition.z + 0.05f * MoveSpeed);
- }
- if (Input.GetKey("down") && !(Input.GetKey("up") || Input.GetKey("left") || Input.GetKey("right")))
- {
- theanim.GetComponent<Animator>().SetBool(charactersfrontwalk, true);
- theanim.GetComponent<Animator>().SetBool(charactersbackwalk, false);
- theanim.GetComponent<Animator>().SetBool(charactersleftwalk, false);
- theanim.GetComponent<Animator>().SetBool(charactersrightwalk, false);
- theanim.GetComponent<Animator>().SetBool(charactersfrontidle, false);
- theanim.GetComponent<Animator>().SetBool(charactersbackidle, false);
- theanim.GetComponent<Animator>().SetBool(charactersrightidle, false);
- theanim.GetComponent<Animator>().SetBool(charactersleftidle, false);
- LeftDirection = false;
- RightDirection = false;
- BackDirection = false;
- FrontDirection = true;
- characters.transform.localPosition = new Vector3(characters.transform.localPosition.x, characters.transform.localPosition.y, characters.transform.localPosition.z - 0.05f * MoveSpeed);
- }
- if (Input.GetKey("left") && !(Input.GetKey("down") || Input.GetKey("up") || Input.GetKey("right")))
- {
- theanim.GetComponent<Animator>().SetBool(charactersfrontwalk, false);
- theanim.GetComponent<Animator>().SetBool(charactersbackwalk, false);
- theanim.GetComponent<Animator>().SetBool(charactersleftwalk, true);
- theanim.GetComponent<Animator>().SetBool(charactersrightwalk, false);
- theanim.GetComponent<Animator>().SetBool(charactersfrontidle, false);
- theanim.GetComponent<Animator>().SetBool(charactersbackidle, false);
- theanim.GetComponent<Animator>().SetBool(charactersrightidle, false);
- theanim.GetComponent<Animator>().SetBool(charactersleftidle, false);
- LeftDirection = true;
- RightDirection = false;
- BackDirection = false;
- FrontDirection = false;
- characters.transform.localPosition = new Vector3(characters.transform.localPosition.x - 0.05f * MoveSpeed, characters.transform.localPosition.y, characters.transform.localPosition.z);
- }
- if (Input.GetKey("right") && !(Input.GetKey("down") || Input.GetKey("up") || Input.GetKey("left")))
- {
- theanim.GetComponent<Animator>().SetBool(charactersfrontwalk, false);
- theanim.GetComponent<Animator>().SetBool(charactersbackwalk, false);
- theanim.GetComponent<Animator>().SetBool(charactersleftwalk, false);
- theanim.GetComponent<Animator>().SetBool(charactersrightwalk, true);
- theanim.GetComponent<Animator>().SetBool(charactersfrontidle, false);
- theanim.GetComponent<Animator>().SetBool(charactersbackidle, false);
- theanim.GetComponent<Animator>().SetBool(charactersrightidle, false);
- theanim.GetComponent<Animator>().SetBool(charactersleftidle, false);
- LeftDirection = false;
- RightDirection = true;
- BackDirection = false;
- FrontDirection = false;
- characters.transform.localPosition = new Vector3(characters.transform.localPosition.x + 0.05f * MoveSpeed, characters.transform.localPosition.y, characters.transform.localPosition.z);
- }
- }
- }
- public class JoystickMove : MonoBehaviour ,IDragHandler,IEndDragHandler
- {
- public static JoystickMove instance=null;
- public float _speed=6f;
- [Tooltip("the joystick radius ")]
- public float R=50f;
- private float _r;
- private Vector2 centerPos;
- private float _h;
- private float _v;
- public float H{
- get{return _h;}
- }
- public float V{
- get{return _v;}
- }
- void Awake(){
- if(instance!=null){
- Destroy(this.gameObject);
- }else{
- instance=this;
- }
- }
- void Start(){
- _r=1f*Screen.width/960f*R; //this to calculate the scale of screen
- centerPos=GetComponent<RectTransform>().position;
- }
- void SetHAndF(Vector2 pos){ //Horizontall and Vertical axes
- Vector2 diff=pos-centerPos;
- float distance=diff.magnitude;
- if(distance>_r){
- pos=centerPos+diff/distance*_r;
- }
- GetComponent<RectTransform>().position=pos;
- Vector2 move=pos-centerPos;
- _h=move.x;
- _v=move.y;
- }
- public void OnDrag(PointerEventData data)
- {
- Vector2 newPos =new Vector2(data.position.x-30f,data.position.y-30f);
- SetHAndF(newPos);
- }
- public void OnEndDrag(PointerEventData data){
- Debug.Log("End Drag"+centerPos);
- GetComponent<RectTransform>().position=centerPos;
- SetHAndF(centerPos);
- }
- }
- using UnityEngine;
- using System.Collections;
- using UnityEngine.EventSystems;
- public class JoystickRotate : JoystickMove
- {
- public static JoystickRotate instance=null;
- void Awake(){
- if(instance!=null){
- Destroy(this.gameObject);
- }else{
- instance=this;
- }
- }
- public class JoystickFire : MonoBehaviour,IPointerDownHandler,IPointerUpHandler
- {
- public static JoystickFire instance=null;
- private bool _fire=false;
- public bool Fire{
- get{return _fire;}
- }
- void Awake(){
- if(instance!=null){
- Destroy(this.gameObject);
- }else{
- instance=this;
- }
- }
- public void OnPointerDown(PointerEventData data){
- _fire=true;
- }
- public void OnPointerUp(PointerEventData data){
- _fire=false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement