Is it possible to remove a part of a name given to a GameObject? For instance:
Im instantiating gameobjects for the use of bullets. I give them the name of the player shooting the bullet. So if a player’s name is “Ben”, his bullets are called Ben’s bullet.
gameObject.name = playerName + “'s
bullet”;
Now I’m trying to use this name to know wich person gives the finishing blow to an other player. And to do this I want find the player object with the same name as the bullet, and update his kill count. So I want to remove the “'s bullet” part from the bullets name.
So long story short: Is it possible to remove a part of a name given to a GameObject?
Hope that this is clear enough en help is really appreciated. Thanks in advance!
Edit: This is the part where the name has to change:
if(other.gameObject.tag == “bullet”){
var colBullet = other.transform.name; playerHealth = playerHealth - 5; if(playerHealth <= 0){ onDie(); //colBullet = colBullet - "'s bullet"; GameObject.Find(colBullet); } }
The name of the collided object is put in the colBullet variable. I printed it and it says: Playername’s bullet. This works but now the only thing it needs is the 's bullet being removed