- Home /
Object upgrades character?
so i have a custom 3rd person character i made. i have a particle effect attached to him so that when mouse down, it will show. the result is whenever you click it will appear as if he is spitting fire. I want it so that when the character walks over an object, the fire he was spitting disapears and a different effect appears. however I am having some trouble understanding what colliders and triggers need to go on what and how i would call on those from script and switch the particle effects.
Answer by ThePunisher · Feb 09, 2013 at 11:01 PM
Does your character use the CharacterController? If so then he should have a rigidbody (if not he'll need one). Now all you need to do is attach collider to the object he will "pick up".
For example, let's say that you have a pill as a powerup. You can attach a box collider to the pill and size it so that it fights tightly on the pill. Then you check isTrigger on the collider component (in the inspector for the pill), which makes it to where your player doesn't actually collide with the pill and instead simply notifies the pill that it has entered its collider. This will allow you to handle the collision yourself.
Now all you have to do is script the events you mentioned.
public class PillScript : MonoBehaviour
{
void OnTriggerEnter(Collider other)
{
if(other.tag == "Player")
{
// Get the special script on your player that allows you to control it.
YourMagicalScript yms = other.gameObject.GetComponent<YourMagicalScript>();
// Disable the fire effect (store/find a reference to it so that you can grab from your character here)
yms.FireEffect.enabled = false;
yms.DifferentEffect.enabled = true;
//And if you want the pill to go away, then all you have to do is call destroy on this scripts GameObject.
Destroy(gameObject);
}
}
}
That code is in c# but the logic is the same no matter what, you'll just need to look up the syntax if you use java.
this helped me understand how i should use colliders properly with OnTriggerEnter thanks.
If it helped answer your question can you please mark the answer as correct.
Your answer
![](https://koobas.hobune.stream/wayback/20220613092429im_/https://answers.unity.com/themes/thub/images/avi.jpg)