I am writing a script to equip weapons when you collide with the pickup version of them. I named all of the pickups: "Pickup Weaponname". Here is the collision part: Code (CSharp): private void OnCollisionEnter(Collision collision) { if ( collision.gameObject.name == "zombie" ) { Destroy(collision.gameObject); } } I want it to split the name of what it collided with (the Collision collision part) into the first 6 characters and the rest of the characters (not counting space). Then if the first 6 chars are Pickup it prints the end part with in the example would be "Weaponname". Please help!
Code (csharp): string pickup = "Pickup EnergySword"; string weaponName = pickup.Substring(7); Debug.Log(weaponName); There's quite a few ways to do this, and many that are much more robust, such as String.Split() with the delimiter being the whitespace. You can read about other string methods here.
@Iron-Warrior Substring does not work it errors this: Assets/Collision.cs(17,46): error CS1061: Type `Collision' does not contain a definition for `Substring' and no extension method `Substring' of type `Collision' could be found (are you missing a using directive or an assembly reference?)