why does this not work
0 down vote favorite so i made 2 scripts and assing it to 2 cubes: cube and cube 1. normaly if you click on cube its set a value so that when you click cube 1 its dispear. if you click cube 1 first it not gonna work. so thats what i tried to make but its do not work and i dont now why
here are my scripts
the script for cube:
using UnityEngine;
using System.Collections;
public class script : MonoBehaviour {
public int test = 0; // make the variable for the value
public void OnMouseDown() // when the user click
{
test = 1; //make the value of test 1
} }
and here is the script for cube 1:
using UnityEngine;
using System.Collections;
public class NewBehaviourScript1 : MonoBehaviour
{
public GameObject a; //make a gameobject
public script script; //make a variable where we put in the script
void OnMouseDown() // when the user click
{
script = a.GetComponent<script>(); // get script
if ( script.test == 1) //test or the variable test in the other script is 1
{
Destroy(gameObject); // destroy the object
}
}
}
can someon please help me
Answer by Lycanthope · Jun 06, 2016 at 12:44 PM
You can not use the same class name as a variable: public script script; , because C # is case sensitive.
Your answer
Follow this Question
Related Questions
Accessing a text variable from another script 0 Answers
GetComponent returning null with no errors 1 Answer
Get instances of a script in children 1 Answer
My health bars image.fillAmount doesnt change. 4 Answers
C# - Cannnot access variable in another script unless I get the component everytime. 1 Answer