- Home /
Newly spawned objects not behaving similar to the original ones.,Newly spawned objects don't behave like the original ones. What do I do?
I am very new to unity (3 days old). I was experimenting with the functions I know and created a basic scene with a player, some obstacles, and some coins. I made a prefab of the coin object and attached a script to it which makes it spin along the y-axis. I then coded it to destroy itself and create another instantiation of the prefab. However, the newly generated coins are not spinning like the original ones that I placed in the scene by the drag and drop method. What am I doing wrong?
the script attached to the prefab --->
using UnityEngine;
public class Coin : MonoBehaviour { public GameObject coin;
void Update()
{
transform.Rotate(Vector3.up, 180 * Time.deltaTime, Space.World);
}
void OnTriggerEnter(Collider trigger)
{
if (trigger.tag == "Player")
{
Vector3 newPosition = new Vector3(Random.Range(-3,3), 0, Random.Range(-3,3));
Instantiate(coin, newPosition, Quaternion.identity);
Destroy(gameObject);
}
}
}
In the inspector, I've connected the public game object coin to the prefab itself. What should I do?
Looks ok to me... are the new coins moving at all or are they completely stationary? Can you check the newly created coins and confirm that this script is attached?
Your answer
Follow this Question
Related Questions
Prefabs won't change? 1 Answer
Can't modify BoxCollider center/size on base prefab 0 Answers
Instantiating Mesh Error - Mesh has Instance added? 1 Answer
How do I reference any instance of a prefab? 1 Answer
Prefab Duplication issue 1 Answer