- Home /
Answer by jonSG · Apr 16, 2014 at 03:09 PM
Though you will not want to do it every frame (GetComponent once in Start()), conceptually you can:
parentscriptclass myParent = transform.parent.GetComponent<parentscriptclass>();
myParent.somepublicmember = "new value";
Answer by Entwicklerpages · Apr 16, 2014 at 03:01 PM
This should work:
this.transform.parent.GetComponent<YourparentScript>().yourVariable = newValue;
But the variable must be public.
$$anonymous$$ake sure your method is right. You are missing the parameter
Oops! I haven't forgot it. I have used < and > for the type. But this editor uses html tags for formatting. I change it.
Answer by JohnnyWK · Oct 23, 2016 at 09:08 AM
You can try this.
MyParentScript myScript = this.GetComponentInParent ();
Now you can call any public function or variable.,
myScript.myVariable = whatever // set variable
myScript.myFucntion() // runs function
Your answer
Follow this Question
Related Questions
Make a simple tree 1 Answer
Distribute terrain in zones 3 Answers
How to read variable from parent object? 2 Answers
Parent object to child of another? 1 Answer
C# Check if parent's script's GameObject variable equals GameObject 2 Answers