if with two conditions not working
I've been working on unity scripting a few days ago and I'm still a beginner so excuse my poor scripting skills I am working on a project where clicking on the "SunRise" gameObject disables the "funnyMoon" gameObject and when clicking on the "letter" gameObject it will be ddestroyed if it is tagged "Sun" Here are the scripts
using UnityEngine;
using System.Collections;
public class SunBoxBehaviour : MonoBehaviour {
// Use this for initialization
public int IsSun = 0;
public GameObject funnyMoon;
void OnMouseDown()
{
IsSun++;
funnyMoon.SetActive (false);
Debug.Log(IsSun);
}
Here is the second script:
using UnityEngine;
using System.Collections;
public class LetterBehaviour : MonoBehaviour {
public SunBoxBehaviour SunBoxBehaviour;
public GameObject SunRise;
void OnMouseDown()
{
if (this.gameObject.tag == "Sun")
{
Debug.Log ("This is Sun");
if(SunBoxBehaviour.IsSun == 1)
{
Destroy (this.gameObject);
Debug.Log ("You made it");
}
}
}
the issue is that it is checking for the first condition: if the letter tagged "Sun" but it's not checking for the other condition. Why is that?
Answer by Mahdi_Alshareefi · Jan 26, 2016 at 10:30 AM
Also I tried to make IsSun a boolean but it didn't work. I know it's more effective and I would appreciate it if someone could help me with that.
Your answer
Follow this Question
Related Questions
Raycast shotgun help! 2 Answers
Unable to create a reference to an instantiated object and alter it? 1 Answer
UCE0001: ';' expected. Insert a semicolon at the end. 1 Answer
Execution order of conditional operators in an if-statement 1 Answer
The If statement condition is false but the if statement stills executes 1 Answer