how to Spawn (or) delete a 2D Gameobject on collision with a particular gameobject?
This script is attached to the prefab which i want spawn
public class StarScript : MonoBehaviour() {
StarSpwaner sp;
// Update is called once per frame
void OnCollisionEnter2D(Collision2D col)
{
if (col.gameObject.tag.Equals("ball")) {
sp.IfcollisionOccur();
}
}
} And this script is attached to Spawning Gameobject
void Start() { randomX = Random.Range(235, 564); randomY = Random.Range(15, 445); RandomSpanPos = new Vector2(randomX, randomY); spawnedobject=Instantiate(Star, RandomSpanPos, Quaternion.identity); }
// Update is called once per frame
public void IfcollisionOccur() {
Destroy(spawnedobject);
randomX = Random.Range(235,564);
randomY = Random.Range(15,445);
RandomSpanPos = new Vector2(randomX,randomY);
spawnedobject= Instantiate(Star, RandomSpanPos, Quaternion.identity);
}
} it wont work Please help me! Thanks in Advancce,
Comment
Your answer

Follow this Question
Related Questions
How to make fast a coroutine 1 Answer
Compiler error 0 Answers
Jittery background when implementing parallax effect 1 Answer
Problem getting components in loaded scene 0 Answers
Instantiating A group of platform and moving them down 0 Answers