Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Checking Collisions with Instanced Prefabs

Discussion in 'Physics' started by Phector, Oct 20, 2015.

  1. Phector

    Phector

    Joined:
    Oct 20, 2015
    Posts:
    1
    I know how to do collision checks, but the problem is:
    I currently have 2 types of bullets, each deals different damage.
    Every time I instantiate a prefab of either one of them the name of the new one becomes "PrefabBullet" + "(Clone)"
    As far as I know unity does not support multiple tags on a single object. And, I dont know where to start with if I have to remove the "(Clone)" string. Does Unity have built-in string helpers or I dig into C# documentation for those, just to remove "(Clone)"?
    Or do you guys know any better method to know which type of bullet the object hit?
     
  2. VorpalSilence

    VorpalSilence

    Joined:
    Oct 22, 2015
    Posts:
    13
    You should be able to set the name of the new object to the name of your prefab to eliminate the addition of '(clone)' to the end of the instantiated objects name. It would look something like:

    GameObject bullet = Instantiate(BulletPrefab,blah,blah) as GameObject;
    bullet.name = BulletPrefab.name;

    Or set the name to some other string as needed etc, then check what the name of the bullet that hit was and apply the appropriate damage.
     
  3. Roni92pl

    Roni92pl

    Joined:
    Jun 2, 2015
    Posts:
    396
    First of all you shouldn't do damage etc based on gameObject name or even tag. Your bullet prefab should have on it Bullet class that contains all needed data(like caliber, explosion force, damage etc.)