Quantcast
Channel: Questions in topic: "javascipt"
Viewing all articles
Browse latest Browse all 1875

Why isn't my animation being played?

$
0
0
The animation works fine with my C# code, but it doesn't play when I try to trigger it from the JS code. JS Code (where the animations doesn't play): #pragma strict var speed : float = 10.0; internal var anim : Animator; var rotation: GameObject; var x : float; var z : float; var angle : float; function Start() { anim = GameObject.Find("Pernas").GetComponent(Animator) as Animator; } function Update () { // Arrows or WASD x = Input.GetAxis("Horizontal") * Time.deltaTime * speed; z = Input.GetAxis("Vertical") * Time.deltaTime * speed; // Animations if (Mathf.Abs(x) > 0.1 || Mathf.Abs(z) > 0.1) anim.SetBool("walk", true); else anim.SetBool("walk", false); // Rotation based on mouse position var playerPlane = new Plane(Vector3.up, transform.position); var ray = Camera.main.ScreenPointToRay (Input.mousePosition); var hitdist = 0.0; if (playerPlane.Raycast (ray, hitdist)) { var targetPoint = ray.GetPoint(hitdist); var targetRotation = Quaternion.LookRotation(targetPoint - gRotacao.transform.position); rotation.transform.rotation = Quaternion.Slerp(rotation.transform.rotation, targetRotation, speed * Time.deltaTime); } // Apply the player's movement transform.Translate(x, 0, z); } } // Update C# Code (working fine): using UnityEngine; using System.Collections; public class Joystick : MonoBehaviour { public GameObject gJoystick; public CNAbstractController MovementJoystick; public Animator anim; public float speed; public float x; public float z; private void Start() { anim = GameObject.Find("Pernas").GetComponent(); } private void Update() { // Receive the joystick's values x = MovementJoystick.GetAxis("Horizontal") * Time.deltaTime * speed; z = MovementJoystick.GetAxis("Vertical") * Time.deltaTime * speed; // Animations if (Mathf.Abs(x) > 0.1 || Mathf.Abs(z) > 0.1) anim.SetBool("walk", true); else anim.SetBool("walk", false); // Apply player's movement transform.Translate(x, 0, z); } } I've tried so many things that I'm starting to think it's an Unity bug. Thanks for any help!

Viewing all articles
Browse latest Browse all 1875

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>