#Hey Folks I have an arena game where
1 messages · Page 1 of 1 (latest)
so far it looks like this, with the green items are the pickups. collision script which increments score and destroys the pickup object is currently on the player object, is that the best way to do it?
In most cases you'll want a script on both objects and they will interact in some way
for example the player object can detect the collision and call a function on whatever it collided with
i ´d leave it on the player
e.g.
void OnTriggerEnter(Collider other) {
if (other.TryGetComponent(out Pickup pickup)) {
pickup.DoPickupAction();
}
}```
^ on the player script
and attach a Pickup script to every pickup-able object
For the pickup script you can do something quite simple:
public class Pickup : MonoBehaviour {
[SerializeField] UnityEvent OnPickup;
public void DoPickupAction() {
OnPickup.Invoke();
}
}```
then using the unityevent you can set up whatever listener you want
very good explained, i am out
cool, thanks.
I'm currently using OnCollisionEnter is it better to use onTriggerEnter?
OnCollisionEnter implies there's a physical collision happening
which is not what I would expect for a pickup
I'd expect the car physics to be unaffected
but it's up to you
yea totaly, there should be no impact on physics at all, but currently there is, so thats just solved another problem 🙂
Yeah you'll need to check the "Is Trigger" box on the pickup's collider