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. Dismiss Notice

Powerful Mograph Tools in Unity - Editor Scripting

Discussion in 'Scripting' started by keenanwoodall, Aug 18, 2014.

  1. keenanwoodall

    keenanwoodall

    Joined:
    May 30, 2014
    Posts:
    595
    So I've been working on a set of Editor scripts for modifying and creating groups of objects in the editor and at runtime. The script I'm stuck on now is a simple recursion script that I'd like to update in the editor as variable values change. It all works fine, but I'd like it to update in the editor (and at runtime).

    Code (js):
    1.  
    2. var spawnAmount : int = 20;
    3. var scaleChange : float = 1.5;
    4. var addYScaleToPosition : boolean = true;
    5. var positionChange : Vector3 = new Vector3(1, 1, 1);
    6. var rotationChange : Vector3 = new Vector3(1, 1, 1);
    7. function Start ()
    8. {
    9.     var clone : GameObject;
    10.     if(spawnAmount > 0)
    11.     {
    12.         clone = Instantiate(this.gameObject, this.transform.position, this.transform.rotation);
    13.         clone.transform.localScale = transform.localScale/scaleChange;
    14.      
    15.         if(!addYScaleToPosition)
    16.         {
    17.             clone.transform.position.x = this.transform.position.x + positionChange.x;
    18.             clone.transform.position.y = this.transform.position.y + positionChange.y;
    19.             clone.transform.position.z = this.transform.position.z + positionChange.z;
    20.         }
    21.         else
    22.         {
    23.             clone.transform.position.x = this.transform.position.x + positionChange.x;
    24.             clone.transform.position.y = this.transform.position.y + renderer.bounds.size.y + positionChange.y;
    25.             clone.transform.position.z = this.transform.position.z + positionChange.z;
    26.         }
    27.      
    28.         clone.transform.rotation.eulerAngles.x = this.transform.rotation.x + rotationChange.x;
    29.         clone.transform.rotation.eulerAngles.y = this.transform.rotation.y + rotationChange.y;
    30.         clone.transform.rotation.eulerAngles.z = this.transform.rotation.z + rotationChange.z;
    31.      
    32.         spawnAmount -=1;
    33.         var newestClone = clone.gameObject.GetComponent("SimpleRecursion");
    34.         newestClone.spawnAmount = spawnAmount;
    35.     }
    36. }
     
    Last edited: Aug 18, 2014
  2. Graph

    Graph

    Joined:
    Jun 8, 2014
    Posts:
    153
    one can never have enough Graph, i vote "mo Graph"; especially OnValidate
     
  3. keenanwoodall

    keenanwoodall

    Joined:
    May 30, 2014
    Posts:
    595
    wut? Uhhh so how can I get it to update?