- Home /
Not getting component properly
How do I fix this so that script 1 gets the string of script 2 (names) and sets it as string dis.
script 1
private string dis;
function Update()
{
RaycastHit hit;
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out hit))
{
if(hit.collider.gameObject.tag == "name")
{
Sink h = hit.collider.gameObject.GetComponent<Sink>();
go = true;
h.names = dis;
}
}
script 2
public class Sink : MonoBehaviour
{
public string names = "Press F to toggle the sink";
}
here is one thing I forgot to put in there
private string dis;
Could you be a bit more precise ? What exactly is the expected result ?
Which script needs to see what string ?
Also, You can edit your first post, to actually make it more concise. ins$$anonymous$$d of adding information in a comment, which is actually hard to assume where it goes.
Answer by jokim · Aug 22, 2014 at 04:59 PM
You're on the right track, but you're actually doing it the wrong way:
instead of
h.names = dis;
You should have :
dis = h.names;
The left hand side of the Equal operator (=) is the one getting the value.
the value you want to assign is on the right hand side of the operator.
Your answer
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
Multiple Cars not working 1 Answer
A node in a childnode? 1 Answer
how toDisable the FPSInputController. 1 Answer
Question on Coroutine and iOS Application Pause Interaction 0 Answers