- Home /
Enable and disabled parent contraint with c#
I am looking to activate and deactivate a parent constraint similarly to how you can enable a script or a collider. Sorry if this is a basic ass bitch question to ask, all my google searches are coming up empty.
This is what I am trying to do, and failing at it miserably.
private GameObject qtipPushParent
void Start()
{
qtipPushParent = GetComponent<ParentConstraint>();
}
void Update()
{
if (bool == true)
{
qtipPushParent .enabled = true;
}else {
qtipPushParent .enabled = false;
}
}
Answer by Anaxis_Studio · Sep 13, 2019 at 11:07 PM
I think you're calling the wrong thing. Check the parent constraint class document.
https://docs.unity3d.com/Manual/class-ParentConstraint.html
You might want the Is Active boolean. Also, the syntax in Start() is incorrect. You either get the component of the gameobject the script is attached to something = gameObject.GetComponent<ComponentName>();
or you get the component from another object that you either have a reference to, or find by gametag in start something = Book.GetComponent<BookScript>().BookName;
public GameObject pushParent;
void Start()
{
// referencing another gameobject? use this.
qtipPushParent = pushParent.GetComponent<ParentConstraint>();
// referencing the ParentConstraint component of the gameobject this script is
// attached to? use this and remove public GameObject pushParent;
qtipPushParent = gameObject.GetComponent<ParentConstraint>();
}
void Update()
{
if (bool == true)
{
qtipPushParent.isActive = true;
}
else
{
qtipPushParent.isActive = false;
}
}
Your answer
Follow this Question
Related Questions
using Aim Constraint 1 Answer
c# How Do I disable current script or anyother script in the program within code? 2 Answers
Multiple Cars not working 1 Answer
how to disable patent components incode 0 Answers
Distribute terrain in zones 3 Answers