Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Character replacement

Discussion in 'Scripting' started by Everscent, Jan 27, 2013.

  1. Everscent

    Everscent

    Joined:
    Jan 27, 2013
    Posts:
    3
    well i wanna make a an rpg game where the character has the ability to change shape but i got the problem where i dont know to make a script for that ability, can this script has the function like i want?

    static var classselected : boolean = false;
    var spawnplace : Transform;
    var firstcharacterobject : GameObject;
    var secondcharacterobject : GameObject;

    function OnGUI ()
    {

    if(classselected == false)
    {
    GUI.Box(Rect(0,0,300,500),GUIContent("Character change shape"));
    }

    if(GUI.Button(Rect(100,100,100,100),GUIContent("First Character")) classselected == false )
    {
    var instance : GameObject = Instantiate(firstcharacterobject, spawnplace.position, spawnplace.rotation);
    classselected = true;
    }

    if(GUI.Button(Rect(100,200,100,100),GUIContent("Second Character")) classselected == false)
    {
    var instance2 : GameObject = Instantiate(secondcharacterobject, spawnplace.position, spawnplace.rotation);
    classselected = true;
    }
    }

    function Update ()
    {
    if (classselected == true)
    {
    Destroy(gameObject);
    }
    }