Trying to make an event triggered Pendulum Group fall
I have got a folder with my Pendulum objects that work when I enable gravity and play the game. I want to be able to start off the game with the gravity unenabled and have a component added to the trigger object that will enable the gravity for the whole folder of objects so that the Pendulum as a whole will swing as it should. I'm having trouble with the component part, as I am new to C# and Unity and this is the most technical thing I have attempted thus far. I have managed to get this code together:
public class TriggerPendulum : MonoBehaviour {
public GameObject Pendulum;
private List<Rigidbody> rope;
public bool GotPendulum;
void OnTriggerEnter (Collider other)
{
if (other.CompareTag ("Pendulum"))
{
Pendulum = other.gameObject;
List<Rigidbody> rope = new List<Rigidbody> ();
rope.Add (Pendulum.GetComponent<Rigidbody> ());
Debug.Log ("Pendulum attached");
GotPendulum = true;
}
if (other.CompareTag ("CanTrigger") && GotPendulum)
{
foreach (Rigidbody i in rope)
{
i.useGravity = true;
}
Debug.Log("Gravity");
}
}
}
When I go to my scene, I place my pendulum group in the trigger volume, set the variable Pendulum, and make sure that I have placed the tags required correctly, with the correct spelling. I set the Use Gravity variable in the children of the Object to false, including the parent.
When I run the game, when the sphere comes and collides with the trigger volume, which has the component added to it, the pendulum doesn't move and I get no messages in the console. I have no idea how to fix this, or even what the problem is. Please help
I don't know if this will help, but here's a picture of part of my screen
Your answer
Follow this Question
Related Questions
Disable gravity (freeze character in mid air) without him flying into space? 1 Answer
Rigidbody.AddForce seems not to do anything 0 Answers
GravityBody hides Rigidbody 1 Answer
Rigidbody doesn't work with my script 0 Answers
3D Game RigidBody Problem 0 Answers