- Home /
Question by
richardzzzarnold · May 03, 2012 at 02:49 PM ·
animationguirandomraycasting
GUI Button vs RayCasting as input for random animation.
I have a curious problem. If I use a GUI button to trigger a randomly selected animation, as follows, I have no problem...
var butteranims = new Array("jump","fly");
function OnGUI() {
if(GUI.Button(Rect(screenPos.x-50,Screen.height - screenPos.y-40,100,100),"",customButton))
{
fly();
}}
function fly()
{
animation.CrossFade(butteranims[Random.Range(0,butteranims.length)]);
animation.CrossFadeQueued("loop");
}
but if i do the same thing but using ray casting instead of GUI button as trigger then i get an error message
var butteranims = new Array("jump","fly");
function Update(){
var ray : Ray = Camera.main.ScreenPointToRay (Input.mousePosition);
var hit : RaycastHit;
for (var touch : Touch in Input.touches) {
if (Input.touchCount > 0 && touch.phase == TouchPhase.Began && Time.time > nextjumptime) {
if (collider.Raycast (ray, hit, 300.0)) {
Debug.DrawLine (ray.origin, hit.point);
fly();
}}}}
function fly(){
animation.CrossFadeQueued(butteranims[Random.Range(0,butteranims.length)]);
animation.CrossFadeQueued("loop");
}
I keep ggetting the error message No appropriate version of 'UnityEngine.Animation.CrossFadeQueued' for the argument list '(Object)' was found.
I have no idea why it should make any difference....
Comment