- Home /
collision between two prefabs.
I have 9 player prefabs which all have tag "Player" and 9 enemy prefabs which all have tag "enemy". I'm trying to detect collision between 1 player cube and 1 enemy cube.
Players have sprite renderer images as similar as enemy prefabs.
Player get spawn at bottom in every new game,and same sprite enemy prefabs are also coming through top side of screen.But the problem is all enemy have same tag so i want to score up with collision of player and enemy which of both have same sprite images. Can you please advice how i can detect the collision?
Thanks In Advance.....
I don't understand the question. You have two sets of objects. Each set has a different tag. When a member of one set collides with a member of another, you want something to happen.
What, specifically, is giving you trouble?
This script is attached to enemy prefabs,and i want to check whether among of all enemy which one has sprite as similar as player.
ERROR : NullReferenceException: Object reference not set to an instance of an object Object$$anonymous$$ovementScript.Update () (at Assets/Scripts/Object$$anonymous$$ovementScript.cs:20)
CODE :
public class Object$$anonymous$$ovementScript : $$anonymous$$onoBehaviour { GameController playerScript; //playerScript
void Start ()
{
playerScript = GetComponent<GameController>();
}
void Update ()
{
if( this.gameObject.GetComponent<SpriteRenderer>().sprite.name == playerScript.m_score$$anonymous$$at )
{
Debug.Log("ScoreUp");
}
//enemy which are moving from top to bottom
gameObject.transform.Translate (new Vector3 (0f,-2.0f * Time.deltaTime,0f));
}
}
So I want to check for same sprite between player and enemy for scoring.
playerScript.m_score$$anonymous$$at is player sprite name defined as string.
Your answer
![](https://koobas.hobune.stream/wayback/20220613185810im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Defender 2d Shooter - Loading Enemies (waves of enemies) 1 Answer
Count Prefabs on builded .apk 0 Answers
Multiplayer different player prefab 0 Answers
PrefabUtility does not exist? 1 Answer
how can i make prefabs keep there inspector varibles 1 Answer