- Home /
Need help with a script that is supposed to get components
First of all, let me explain: I have an AI (Ethan Third Person AI) in my scene and I parented a "IsTrigger = True" Sphere to the AI GameObject
Now I wanted the script to get the Components of the AI so that I can change the speed value when the player enters and exits the sphere... (By OnEnterTrigger (Collider player) { if(tag == "Player") } ) 1.: The script is on the cube, not the AI 2.: I want to get the Walk and Anim Speed Variables, so that I can change them 3.: I have no idea how to solve this and I would be very happy if anyone could help me! (New to programming obviously)
I would be so happy if someone would show me a smarter way to solve this or... basically just help me with the script.
Sincerely, Xanthum
What exactly do you want to do? Get the components of a game object?
Answer by TheSOULDev · Sep 09, 2017 at 02:35 PM
So, from what I understand, you want to access a set of components and change them upon entering a trigger with the AI. You would do it with something like this:
void OnTriggerEnter(Collider col)
{
if(col.tag == "Player")
{
SomePlayerScript Container = col.gameObject.GetComponent<SomePlayerScript>();
Container.Walk = someValue;
Container.AnimSpeedVariables = someOtherValue;
}
}
But I honestly don't understand what you want to do 100% so if my solution isn't what you're looking for, try to explain it better to us.
Yes, I do want to change the walk speed and the animation speed upon entering the trigger. But I'm new to program$$anonymous$$g, so I don't really now what a "Container" is and how to set it up.
I want to change the "$$anonymous$$ove Speed $$anonymous$$ultiplier" and the "Anim Speed $$anonymous$$ultiplier", but I don't know how to set up this "SomePlayerScript" and what code to put in it.
I would be happy if anyone could explain!
Your answer

Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
EnemyAI C# Error 1 Answer
AI Look at X axis more efficient code 1 Answer
Need Help making Pong AI beatable 1 Answer