hey everyone, what i am trying to do is the following: i want there to be an object, lets call it a base, and when an object is created near the base, it automaticaly detects what is the one placed, say a generator or a miner, and starts changing variables accordingly to its type. i cant use colliders tho because im using a raycast to place the object and they would interfier, that and they dont seem to be working for me. so i wanted you guys to give me an idea on how to do this, no scripts or as few as possible necause i still want the challenge, ty all.
There’s an interesting trick that may solve your problem: add a sphere trigger with the desired radius to the base object, then add a kinematic rigidbody to it and a simple code to its script:
void OnTriggerEnter(Collider other){
print("Aha! Detected object "+other.name);
}
void FixedUpdate(){
// simulate trigger movement in order to detect colliders:
rigidbody.position = transform.position;
}
The trick is to force a pseudo-movement every FixedUpdate: this allows the trigger (which has a kinematic rigidbody) to detect any collider that’s created inside the range - use OnTriggerEnter in order to get info about what was created and to update the variables you want.
About the Raycast: you may uncheck Raycasts Hit Triggers in the Physics Manager, or just select layer Ignore Raycast in the trigger object - both alternatives make the trigger invisible for Raycasts.