- Home /
Question by
alexander11 · Dec 18, 2014 at 09:52 PM ·
c#functionfloat
How do i make a float match to another float on other script
im having some trouble anyone help me i declare a float in script1 and declare another float in script2 and im trying to make it when a number is equal it has a function like this one but im having trouble
//script1
public class script1 : MonoBehaviour{
public float A;
public script2 s2;
void Update(){
if (A == s2.B)
{
print("True");
}
else
{
print("False");
}
}
}
script2 :
//script2
public class script2: MonoBehaviour{
public float B;
}
any help please
Comment
Answer by bubzy · Dec 18, 2014 at 09:59 PM
public class script2: MonoBehaviour{
public float B;
public GameObject tempObject;
public script1 tempScript;
void Start()
{
tempScript = tempObject.GetComponent<script1>(); //this is assuming that you have dragged a gameObject with script1 attached to it in the inspector.
B = tempScript.A;
}
}
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
summing up items price in runtime 1 Answer
My function doesn't appears in the OnClick button script 5 Answers