- Home /
Joystick and Blend Trees
Hey I have a game project for mobile. But firslty I have to create some animations for movements. I have a joystick code and I can move objects but I cannot give my animations to my character.
using System.Collections; using System.Collections.Generic; using UnityEngine.UI; using UnityEngine.EventSystems; using UnityEngine;
public class joystick : MonoBehaviour, IPointerDownHandler, IPointerUpHandler, IDragHandler{ public Animator animasyon; public GameObject kup; Image JoyArka; Image Joystick; Vector3 griliv; // Use this for initialization void Start() { animasyon = GetComponent(); JoyArka = gameObject.transform.GetComponent(); Joystick = gameObject.transform.GetChild(0).GetComponent(); }
public void OnDrag(PointerEventData ped)
{
Vector2 pozisyon;
if(RectTransformUtility.ScreenPointToLocalPointInRectangle(JoyArka.rectTransform,ped.position,ped.enterEventCamera,out pozisyon))
{
pozisyon.x = (pozisyon.x / JoyArka.rectTransform.sizeDelta.x);
pozisyon.y = (pozisyon.y / JoyArka.rectTransform.sizeDelta.y);
griliv = new Vector3(pozisyon.x * 2, 0, pozisyon.y * 2);
griliv = (griliv.magnitude > 1.0f) ? griliv.normalized : griliv;
Joystick.rectTransform.anchoredPosition = new Vector3(griliv.x * Joystick.rectTransform.sizeDelta.x, griliv.z * Joystick.rectTransform.sizeDelta.y/2);
}
}
public void OnPointerUp(PointerEventData ped)
{
griliv = Vector3.zero;
Joystick.rectTransform.anchoredPosition = Vector3.zero;
}
public void OnPointerDown(PointerEventData ped)
{
OnDrag(ped);
}
// Update is called once per frame
void Update () {
kup.transform.position += griliv * Time.deltaTime * 5;
}
}
I dont know why but I couldnt set above part of the codes as it should be for this website. But the point is, I have already made animator and GetComponent stuff but I dont know what to do in void update. Can please help ?
Your answer
Follow this Question
Related Questions
Blend Tree can't change animation when it gets minus value. 1 Answer
Joystick Angle Problems 0 Answers
Change the position of the Joystick by tap 2 Answers
Xbox controller joystick axis small movements? 1 Answer
How to implement joystick? 0 Answers