Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- using UnityEngine.UI;
- [RequireComponent(typeof(Rigidbody))]
- public class PlayerMoveController : MonoBehaviour {
- // PUBLIC
- public SimpleTouchController leftController;
- public Transform _rotation;
- public Animator animate;
- public RectTransform _jost,_center;
- public GameObject pers;
- public SimpleTouchController rightController;
- public float speedMovements = 5f;
- public float speedContinuousLook = 100f;
- public float speedProgressiveLook = 3000f;
- public bool continuousRightController = true;
- // PRIVATE
- private Rigidbody _rigidbody;
- private Vector2 localEulRot;
- private Vector2 prevRightTouchPos;
- void Awake()
- {
- _rigidbody = GetComponent<Rigidbody>();
- //rightController.TouchEvent += RightController_TouchEvent;
- //rightController.TouchStateEvent += RightController_TouchStateEvent;
- }
- public bool ContinuousRightController
- {
- set{continuousRightController = value;}
- }
- void RightController_TouchStateEvent (bool touchPresent)
- {
- if(!continuousRightController)
- {
- prevRightTouchPos = Vector2.zero;
- }
- }
- void RightController_TouchEvent (Vector2 value)
- {
- if(!continuousRightController)
- {
- Vector2 deltaValues = value - prevRightTouchPos;
- prevRightTouchPos = value;
- }
- }
- void FixedUpdate()
- {
- animate.SetBool ("Walk", true);// move
- _rigidbody.MovePosition(transform.position + (transform.up * leftController.GetTouchPosition.y * Time.deltaTime * speedMovements) +
- (transform.right * leftController.GetTouchPosition.x * Time.deltaTime * speedMovements) );
- if (continuousRightController)
- {
- transform.localEulerAngles = new Vector2(transform.localEulerAngles.x - rightController.GetTouchPosition.y * Time.deltaTime * speedContinuousLook,
- transform.localEulerAngles.y + rightController.GetTouchPosition.x * Time.deltaTime * speedContinuousLook);
- }
- if(Mathf.Abs(_center.anchoredPosition.x) > 0 || Mathf.Abs(_center.anchoredPosition.y) > 0)
- {
- Vector2 heading = (Vector2)_center.anchoredPosition;
- Vector2 direction = heading / heading.magnitude;
- float sdx = direction.x;
- float sdy = direction.y;
- float sR = Mathf.Atan2(sdx, sdy);
- float sD = 360 * sR / (2 * Mathf.PI);
- _rotation.transform.rotation = Quaternion.Euler(0.0f, 0.0f, -sD);
- }
- else
- {
- animate.SetBool ("Walk", false);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement