I am not quiet sure what am doing wrong in the below code. In animation parameter Happy_A boolean keep turning on and off repeatedly.
Code:
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine.UI;
namespace Vuforia
{
public class L_01_gameManager : MonoBehaviour
{
// Vuforia Tracker Reference
private targetTracker targetObject = null;
public GameObject[] correctAnswers;
Material[] CA_mats;
public GameObject Answer_System;
public List<GameObject> answerPrefabs;
public Transform[]spawnPos;
//Questions
public List<GameObject> L_Questions;
public string questionLabel;
private bool[] S_Ans = new bool[7];
private bool[] CA_A = new bool[9];
private bool[] CS_A = new bool[9];
private bool[] CA_D = new bool[2];
// Spinner
public Transform[] wayPoints;
public GameObject selectionSpinner;
private Vector3 spinner_TargetScale;
// SolutionBox
public GameObject solutionBox;
private Animator solutionBox_A;
// Winnie GO
public GameObject winnie;
private Animator winnie_A;
private Material winne_M;
private bool winnieHappy_T;
private bool[] Anim_B = new bool[5];
private bool[] winnie_A_B = new bool[9];
void Start()
{
// Vuforia Extensions
targetObject = GameObject.Find("ImageTarget").GetComponent<targetTracker>();
targetObject.OnTrackingFound += trackingFound;
targetObject.OnTrackingLost += trackingLost;
solutionBox_A = solutionBox.GetComponent<Animator>();
winnie_A = winnie.GetComponent<Animator>();
winne_M = winnie.GetComponentInChildren<SkinnedMeshRenderer>().material;
}
void Update()
{
correctAnswers_Sys();
answerSys();
spinnerAnim();
StartCoroutine(winnieAnim());
}
public void trackingFound()
{
StartCoroutine(fadeEffect(1.0f,1.0f));
StartCoroutine(NumGen());
winnie_A.SetTrigger("Taunt_A");
}
public void trackingLost()
{
}
IEnumerator fadeEffect(float aValue, float aTime)
{
float alpha = winne_M.color.a;
for(float t = 0.0f; t < 1.0f; t += Time.deltaTime/aTime)
{
Color newColor = new Color (1,1,1,Mathf.Lerp(alpha,aValue,t));
winne_M.color = newColor;
yield return null;
}
}
IEnumerator winnieAnim()
{
if(winnie_A_B[0])
{
winnie_A.SetBool("Happy_A",true);
yield return new WaitForSeconds(1.0f);
//winnie_A.SetBool("Happy_A",false);
winnie_A_B[0] = false;
}
if(!winnie_A_B[0])
{
winnie_A.SetBool("Happy_A",false);
}
//winnie_A.SetBool("Idle_A",true);
yield return null;
}
void answerSys()
{
if(Input.GetMouseButtonDown(0))
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast(ray, out hit))
{
for (int i = 0; i<L_Questions.Count; i++)
{
if(hit.collider.gameObject == L_Questions[0].gameObject)
{
S_Ans[0] = true;
questionLabel = "Selected Question index is:"+ i.ToString();
selectionSpinner.transform.position = wayPoints[0].transform.position;
}
if(hit.transform.tag == "Three" && S_Ans[0])
{
Debug.Log("ClickedRight 3!");
CA_A[0]= true;
S_Ans[0] = false;
}
if(hit.collider.gameObject == L_Questions[1].gameObject)
{
S_Ans[1] = true;
questionLabel = "Selected Question index is:"+ i.ToString();
selectionSpinner.transform.position = wayPoints[1].transform.position;
}
if(hit.transform.tag == "Five" && S_Ans[1])
{
Debug.Log("ClickedRight 5!");
CA_A[1]= true;
S_Ans[1] = false;
}
if(hit.collider.gameObject == L_Questions[2].gameObject)
{
S_Ans[2] = true;
questionLabel = "Selected Question index is:"+ i.ToString();
selectionSpinner.transform.position = wayPoints[2].transform.position;
}
if(hit.transform.tag == "Seven" && S_Ans[2])
{
Debug.Log("ClickedRight 7!");
CA_A[2]= true;
S_Ans[2] = false;
}
if(hit.collider.gameObject == L_Questions[3].gameObject)
{
S_Ans[3] = true;
questionLabel = "Selected Question index is:"+ i.ToString();
selectionSpinner.transform.position = wayPoints[3].transform.position;
}
if(hit.transform.tag == "Nine" && S_Ans[3])
{
Debug.Log("ClickedRight 9!");
CA_A[3]= true;
S_Ans[3] = false;
}
if(hit.collider.gameObject == L_Questions[4].gameObject)
{
S_Ans[4] = true;
questionLabel = "Selected Question index is:"+ i.ToString();
selectionSpinner.transform.position = wayPoints[4].transform.position;
}
if(hit.transform.tag == "Eleven" && S_Ans[4])
{
Debug.Log("ClickedRight 11!");
CA_A[4]= true;
S_Ans[4] = false;
}
if(hit.collider.gameObject == L_Questions[5].gameObject)
{
S_Ans[5] = true;
questionLabel = "Selected Question index is:"+ i.ToString();
selectionSpinner.transform.position = wayPoints[5].transform.position;
}
if(hit.transform.tag == "Five" && S_Ans[5])
{
Debug.Log("ClickedRight 5 Again once!");
CA_A[5]= true;
S_Ans[5] = false;
}
if(hit.collider.gameObject == L_Questions[6].gameObject)
{
S_Ans[6] = true;
questionLabel = "Selected Question index is:"+ i.ToString();
selectionSpinner.transform.position = wayPoints[6].transform.position;
}
if(hit.transform.tag == "Zero" && S_Ans[6])
{
Debug.Log("ClickedRight 0!");
CA_A[6]= true;
S_Ans[6] = false;
}
if(hit.collider.gameObject == L_Questions[7].gameObject)
{
CA_D[0]= true;
questionLabel = "Selected Question index is:"+ i.ToString();
selectionSpinner.transform.position = wayPoints[7].transform.position;
}
if(hit.transform.tag == "Five" && CA_D[0])
{
Debug.Log("ClickedRight 5 Again twice!");
CA_A[7]= true;
S_Ans[0] = false;
}
if(hit.collider.gameObject == L_Questions[8].gameObject)
{
CA_D[1] = true;
questionLabel = "Selected Question index is:"+ i.ToString();
selectionSpinner.transform.position = wayPoints[8].transform.position;
}
if(hit.transform.tag == "Nine" && CA_D[1])
{
Debug.Log("ClickedRight 9 Again once!");
CA_A[8]= true;
CA_D[1] = false;
}
}
}
}
}
void correctAnswers_Sys()
{
CA_mats = new Material[correctAnswers.Length];
for(int i = 0; i<correctAnswers.Length; i++)
{
CA_mats _= correctAnswers*.renderer.material;*_
_ correctAnswers*.renderer.material.color = new Color(0,0,0,0);*_
* if(CA_A[0]== true)
_ {
correctAnswers[0].renderer.material.color = new Color(0,1,0,1);_
winnie_A_B[0]= true;*
* }*
* if(CA_A[1]== true)
_ {
correctAnswers[1].renderer.material.color = new Color(0,1,0,1); _
winnie_A_B[0] = true;*
* } *
* if(CA_A[2]== true)
_ {
correctAnswers[2].renderer.material.color = new Color(0,1,0,1); *_
* } *
* if(CA_A[3]== true)
_ {
correctAnswers[3].renderer.material.color = new Color(0,1,0,1); *_
* }*
* if(CA_A[4]== true)
_ {
correctAnswers[4].renderer.material.color = new Color(0,1,0,1); *_
* } *
* if(CA_A[5]== true)
_ {
correctAnswers[5].renderer.material.color = new Color(0,1,0,1); *_
* } *
* if(CA_A[6]== true)
_ {
correctAnswers[6].renderer.material.color = new Color(0,1,0,1); *_
* } *
* if(CA_A[7]== true)
_ {
correctAnswers[7].renderer.material.color = new Color(0,1,0,1); *_
* }*
* if(CA_A[8]== true)
_ {
correctAnswers[8].renderer.material.color = new Color(0,1,0,1);*_
* } *
* }*
* }*
* void spinnerAnim()*
* {*
_ selectionSpinner.transform.Rotate(Vector3.upTime.deltaTime1000,Space.World);
* }*_
IEnumerator NumGen()
* {*
* yield return new WaitForSeconds(0.7f);*
* solutionBox_A.SetBool(“slideIn”,true);*
* yield return new WaitForSeconds(1.5f);*
* numRand();*
* }*
* void numRand()*
* {*
* for(int i = 0; i<spawnPos.Length; i++)*
* {*
* int answerClone= Random.Range(0,answerPrefabs.Count); *
GameObject clone = Instantiate(answerPrefabs[answerClone],spawnPos_.position,spawnPos*.rotation)as GameObject;
clone.transform.localScale = new Vector3(0.5f,0.5f,0.5f);_
clone.transform.parent = Answer_System.transform;
_ answerPrefabs.RemoveAt(answerClone);
}*_
* }*
}
}