Answer the question
In order to leave comments, you need to log in
How to add a prefab as a trace in the place where the sphere bounces?
Please help write the code for this case. I know it's simple, but I don't know where to start.
Here is the link to the assets. There's a stage inside and a prefab trace.
https://onedrive.live.com/?authkey=%21AC03c9FLZ%2D...
Answer the question
In order to leave comments, you need to log in
Create a script to attach to the wall. What's on the sphere, what's on the wall in the Collider, turn on Is Trigger. There must also be a Rigidbody component in the sphere or wall. And don't forget to include the prefab. Here is the script:
public GameObject prefab;
Collider obj;
private bool onTrigger = false;
void OnTriggerEnter(Collider other)
{
obj = other;
onTrigger = true;
}
void FixedUpdate()
{
if (onTrigger == true)
{
Instantiate(prefab, obj.gameObject.transform.position, Quaternion.identity);
onTrigger = false;
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question