Search Unity

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);
    }
    }