using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Linq;
public class CardMechanics : MonoBehaviour
{
public StatusBars statusBars;
GameObject ZombieCard1, ZombieCard2, ZombieCard3, ZombieCard4, ZombieCard5;
int randomnumberpicker;
private static bool leftChoice, rightChoice;
void Start()
{
statusBars = FindObjectOfType<StatusBars>();
}
//Wouldn't ZombieCards() get called before you have a chance to trigger OnMouseDown(),
//causing it to instantiate a card (which I presume would create an object with tag "Card") and
//result in it never entering that initial if statement in ZombieCards() again?
void Update()
{
if(GameObject.FindWithTag("Card") == null)
{
ZombieCards();
leftChoice = false;
rightChoice = false;
}
}
void ZombieCards()
{
randomnumberpicker = Random.Range(0, 6);
Debug.Log(randomnumberpicker);
switch (randomnumberpicker) {
case 0:
{
ZombieCard1 = Instantiate(Resources.Load("Frontcard1")) as GameObject;
ZombieCard1.transform.Translate(0, -1, 0);
if (leftChoice == true)
{
Debug.Log("Jesus Marty! you fixed it! Great Scott!");
}
break;
}
case 1:
{
ZombieCard2 = Instantiate(Resources.Load("Frontcard2")) as GameObject;
ZombieCard2.transform.Translate(0, -1, 0);
break;
}
case 2:
{
ZombieCard3 = Instantiate(Resources.Load("Frontcard3")) as GameObject;
ZombieCard3.transform.Translate(0, -1, 0);
break;
}
case 3:
{
ZombieCard4 = Instantiate(Resources.Load("Frontcard4")) as GameObject;
ZombieCard4.transform.Translate(0, -1, 0);
break;
}
case 4:
{
ZombieCard5 = Instantiate(Resources.Load("Frontcard5")) as GameObject;
ZombieCard5.transform.Translate(0, -1, 0);
break;
}
}
}
void OnMouseDown()
{
if (gameObject.CompareTag("LeftArrow"))
{
leftChoice = true;
Debug.Log("Left arrow is working");
}
if (gameObject.CompareTag("RightArrow"))
{
rightChoice = true;
Debug.Log("Right arrow is working");
}
}
}
The problem with this code is that my Left or Right choice bool statements are never initializing the if statement within case 0:
Any help would be appreciated! I think it because of a logic area, the fact that OnMouseDown never has a chance to get triggered. Any help would be much appreciated.
Still new to coding so any pointers would also be very helpful.