Search Unity

Best way to do this

Discussion in 'Scripting' started by Falin, Jul 22, 2011.

  1. Falin

    Falin

    Joined:
    Sep 29, 2009
    Posts:
    242
    So basically I want to Instantiate a cube that extrude/scale itself. but when He hits something he stops.
    Image url to show what I had in mind
    http://dl.dropbox.com/u/35514683/Untitled-2.html
    So what is the best way/method to handle this?


    Because now I scale it and use OnTriggerEnter, but it stops after the wall(for example)
    And sometimes it scales it to in the opposite(negative) direction then I want.
     
  2. eTag96

    eTag96

    Joined:
    Oct 24, 2010
    Posts:
    110
    turn isTrigger off, and put your stopping code in a

    OnCollisionEnter() function.
     
  3. eTag96

    eTag96

    Joined:
    Oct 24, 2010
    Posts:
    110
    Code (csharp):
    1. var stop = false;
    2.  
    3. function Update() {
    4.    if(!stop) {
    5.       //scale....
    6.    }
    7. }
    8.  
    9. function OnCollisionEnter() {
    10.    stop = true;
    11. }
     
  4. Falin

    Falin

    Joined:
    Sep 29, 2009
    Posts:
    242
    Thanks that worked
     
  5. bigmisterb

    bigmisterb

    Joined:
    Nov 6, 2010
    Posts:
    4,221
    What concerns me greatly about this is that your doing a mathematical scale. I am not sure that the collision will register consistently.
     
  6. Jessy

    Jessy

    Joined:
    Jun 7, 2007
    Posts:
    7,325