Hi I'm very new to Unity (using 4.3) and have hit a snag with animation. The problem is I cannot tell if this is a bug in Unity (as it feels a bit like one) or I'm doing something wrong. My simple aim is to be able to control the speed of an animation state via code. So as an example I have a spinning cube sequence and I want to slow it down over time but if the player clicks it it speeds up. So I dug around the forums and discovered that with the animator controller you cannot specify speed for an individual state. However I found a workaround using blend trees which did work!!! I created a blend tree on my state and used the same animation clip but changed the threshold and speed. I set this upto a float and it worked!!!! However as soon as i started to add another transition to control another aspect the original code no longer functioned. No matter what I do now in the project as in delete the animation and controllers and do afresh it is still broken? Anyone any ideas on why this would occur? I have pasted my code below...bu tlike i say this was working great until I went in to add a new transition. Code (csharp): #pragma strict private var cube:GameObject; private var cubeAni:Animator; public var cubeSpeed:float = 3; public var cubeMaxSpeed:float = 4; private var speedBoost:float = 0.5; function Start () { cube = GameObject.FindWithTag("cube"); cubeAni = cube.GetComponent("Animator"); } function Update () { cubeAni.SetFloat("Speed", cubeSpeed); if (Input.GetMouseButtonDown(0)) { //Create physics2d raycast to detect location of click var hitm : RaycastHit2D = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(Input.mousePosition), Vector2.zero); if(hitm.collider.gameObject.tag == "cube") { cubeSpeed = cubeSpeed + speedBoost; cubeAni.SetFloat("Speed", cubeSpeed); Debug.Log("clicked the cube" + cubeAni.speed); } } } thanks in advance ade
Ok I think I have solved this It was how i was trying to access the Animator component so changed: cube = GameObject.FindWithTag("cube"); cubeAni = cube.GetComponent("Animator") TO: cubeAni = GameObject.Find("cube").GetComponent(Animator); and it seems to work again