Hey, so my problem is that after I remove everything from the list and it gets out of the loop it goes back 1.
What I think is there is a problem with using List.add with the raycast It could be not true I am just guessing Can someone tell me the reason please and how to fix it? Here is the code
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class Check : MonoBehaviour {
public GameObject[] gob;
public GameObject gob1;
public int checker;
List<GameObject> Cards = new List<GameObject>();
public static int chec = 0;
RaycastHit hit;
public FlipAD s;
void Start () {
Debug.Log ("START!");
}
// Update is called once per frame
void Update () {
if (Input.GetMouseButtonDown (0)) {
if (Physics.Raycast (Camera.main.ScreenPointToRay (Input.mousePosition), out hit)) {
Cards.Add(hit.collider.gameObject); //HERE IS WHERE I ADD TO THE LIST
Debug.Log (hit.collider.tag);
}
}
Debug.Log(Cards.Count);
//Debug.Log (hit.collider.tag);
Debug.Log (chec);
if(Cards.Count == 2){
Debug.Log("Yup Rotation starts here");
float rot = 0f;
while (rot < 180f){
Cards[0].transform.Rotate(new Vector3(0,90,0) * Time.deltaTime);
Cards[1].transform.Rotate(new Vector3(0,90,0) * Time.deltaTime);
rot = rot + 90f * Time.deltaTime;
}
int i =0;
while (Cards.Count !=0){ //HERE WHERE DO I REMOVE EVERYTHING FROM THE LIST
Cards.RemoveAt(i);
i++;
}
} // AFTER LEAVING THE IF CONDITION THE LIST GOES BACK 1 WITHOUT CLICKING ON ANOTHER OBJECT
if (Input.GetMouseButtonDown (0) && (chec) == 2 && hit.collider.tag == "AD") {
Debug.Log ("first if");
gob = GameObject.FindGameObjectsWithTag ("AD");
Invoke ("Destro", 4);
chec = 0;
} else if (Input.GetMouseButtonDown (0) && (chec) == 20 && hit.collider.tag == "D") {
Debug.Log ("first if");
gob = GameObject.FindGameObjectsWithTag ("D");
Invoke ("Destro", 4);
chec = 0;
} else if (Input.GetMouseButtonDown (0) && (chec) == 200 && hit.collider.tag == "S") {
Debug.Log ("first if");
gob = GameObject.FindGameObjectsWithTag ("S");
Invoke ("Destro", 4);
chec = 0;
} else if (Input.GetMouseButtonDown (0) && (chec) == 2000 && hit.collider.tag == "RAK") {
Debug.Log ("first if");
gob = GameObject.FindGameObjectsWithTag ("RAK");
Invoke ("Destro", 4);
chec = 0;
} else if (Input.GetMouseButtonDown (0) && (chec) == 20000 && hit.collider.tag == "FUJ") {
Debug.Log ("first if");
gob = GameObject.FindGameObjectsWithTag ("FUJ");
Invoke ("Destro", 4);
chec = 0;
} else if (Input.GetMouseButtonDown (0) && (chec) == 200000 && hit.collider.tag == "UQ") {
Debug.Log ("first if");
gob = GameObject.FindGameObjectsWithTag ("UQ");
Invoke ("Destro", 4);
chec = 0;
} else if (Input.GetMouseButtonDown (0) && (chec) == 2000000 && hit.collider.tag == "AJ") {
Debug.Log ("first if");
gob = GameObject.FindGameObjectsWithTag ("AJ");
Invoke ("Destro", 4);
chec = 0;
} else if (chec!= 0 && chec != 1 && chec != 2 && chec != 10&& chec != 20&& chec != 100&& chec != 200&& chec != 1000&& chec != 2000&& chec != 10000&& chec != 20000&& chec != 100000&& chec != 200000&& chec != 1000000&& chec != 2000000){
Debug.Log("First False");
chec = 0;
}
}
void Destro(){
for (int i =0; i<2; i++) {
Destroy (gob *);*
-
}*
-
}*
}
[55887-list1.png|55887]*
*