Hi, is there any way that I can instantiate something only at game objects that have a collider attached to it? I don't want to see the prefab travel, just instantiate at a collider (a wall).
For example, if the player is facing toward a wall that is far away and I click the fire key (Input.GetAxis("Fire")) the prefab would instantiate at the collision (the wall)?
public class InstPrefabs : MonoBehaviour {
private void InstThePreFab() {
Vector3 fwd = transform.TransformDirection(Vector3.forward);
if (Physics.Raycast(transform.position, fwd, Mathf.Infinity)) {
Instantiate(prefab, transform.position, Quaternion.Identity);
}
}
}
This is kinda funky.
What I have, is when anything (both raycasts and projectiles) collide with something then it plays the collision sound (which is the sound attached to the prefab in the audiosource).