Hi…
I have some problem with this topic. I have one object, if I touch it I want it play animation A, then when I touch again, different animation will played.
with my code just played the last animation. Please help me ! Thanks
Here is my code:
using UnityEngine;
using System.Collections;
public class TriggerObj52 : MonoBehaviour {
public Transform target;
public Animation animObj;
public bool t1;
public bool t2;
public bool t3;
// Update is called once per frame
void Update () {
if (Input.GetMouseButton (0) ) {
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if(Physics.Raycast(ray, out hit) && hit.transform == target){
if(t1==true && t2==true){
animObj.Play("5_2");
t1=false;
}
if(t2=true && t1==false) {
animObj.Play("5_3");
t2=false;
}
if(t3=true && t2==false) {
animObj.Play("5_4");
t3=false;
t1 = t2 = true;
}
}
}
}
}
using UnityEngine;
using System.Collections;
public class TriggerObj52 : MonoBehaviour {
public Transform target;
public Animation animObj;
private int clipIndex = 0;
// Update is called once per frame
void Update () {
if (Input.GetMouseButton (0) ) {
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if(Physics.Raycast(ray, out hit) && hit.transform == target){
switch ( clipIndex ) {
case 0: animObj.Play("5_2"); break;
case 1: animObj.Play("5_3"); break;
case 2: animObj.Play("5_4"); break;
}
clipIndex = (clipIndex + 1) % 3;
}
}
}
}