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

little problem

Discussion in 'Scripting' started by gk104, May 28, 2014.

  1. gk104

    gk104

    Joined:
    Apr 25, 2014
    Posts:
    57
    I'll explain how it works shortly, you have 20 seconds to destroy all the cubes that displayed on the screen, every cube that destroyed will give you 1 point and than if all cubes destroyed so a new bunch of cubes will appear and you will have more 10-15 sec.

    when cube destroyed so its renderer and collision is off. when all cubes on screen destroyed so all of the cubes renderer and collision is set to true.

    problem is that when all cubes set to true after destroying them, I CANT USE THE METHOD OnMouseDown again to make its hp lower and destroy them.

    CODE CENCORED
     
    Last edited: May 31, 2014
  2. paranoidx

    paranoidx

    Joined:
    Apr 17, 2014
    Posts:
    43
    You got a couple of redundant logic.
    Code (csharp):
    1.  
    2. if(hp <= 0)
    3.     {
    4.     cube = false; //set cube to false
    5.     hp = 0;
    6.     if(cube == false) { // cube is always false
    7.     cube = false; // cube was false to begin with
    8.  
    from your logic, each cube has 100hp, each click takes 30hp off. Therefore if cube has been clicked 4x(a.counter = 4), its hp is reset to 1 and its hidden(collider/render off) < player cannot click since render is off.

    "Somehow" a.counter gets to 15, and its set back to hp=100,render etc..

    if thats the logic you want, you need another object that will announce to all the cube to wake up e.g. GameController. At this point i still dont know who keeps the timer i.e. 20s, 10-15s.

    so your game controller starts by finding all the cubes and then on first timer 20s reached, reset all the cubes a.counter to 15 which would in turn reset the cubes and consequently runs another 10-15s.
     
    Last edited: May 28, 2014
  3. gk104

    gk104

    Joined:
    Apr 25, 2014
    Posts:
    57
    the whole code was messed up like a junk..
    anyway can you be more specific with that GameController thing, i didnt understand that really good
     
  4. gk104

    gk104

    Joined:
    Apr 25, 2014
    Posts:
    57
    HELP