loxfear
1
ok, i need some help, i tried a few places and didn’t find what i was looking for, i need a script like this:
its on my camera, but checks if obj1, is colliding with an object with a certain tag
this is what i tryed:
void OnCollisionEnter(Collision retAdd){
if(retAdd.gameObject.tag == “BuildObject”)
{
print(“colliding!”);
}
retAdd is the object i want to chek if is colliding
2 Answers
2
fafase
2
You could use events
Obj1.cs
public delegate void CollisionEvent();
public static event OnCollisionEvent OnCollision;
void OnCollisionEnter(Collision retAdd)
{
if(retAdd.gameObject.tag == "BuildObject") {
if(OnCollision != null) OnCollision();
}
}
Now on your cam:
Cam.cs
void Awake()
{
Obj1.OnCollision += OnCollisionSubscriber;
}
void OnCollisionSubscriber()
{
print("Object collided");
}
The method gets called automatically when the event is happening.
F3RILLA
3
If the solution above doesn’t work out for you, try this. I asked this question a few days ago and that helped me out - Collision Problem - Floor Button & Character Controller - Unity Answers
does both objects colliding need to have a collider? or is it able to tell if they are intersekting?
– loxfearretAdd does not have an colider:/
– loxfearYou need collider and at least one of them needs a rigidbody
– fafase@loxfear how did it go? Please maintain feedback with the answerer.
– vexe