Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - seamusc

Pages: [1]
1
 I am trying to drag a prefab into UIroot and vice versa, could anyone please point me in the right direction.. I've also tried putting the entire game asset under UIroot for drag and drop, no luck there.
 
 Is there any tutorials on how to use the NGUI UI to drag around sprites that are not in UIroot, do you use anchors to do this?

 I am going to review the Inventory Drag and drop tutorial again to see how the pieces of armor are created on the box after the drag and drop. 

 Thanks for any direction.
 
 Seamus

2
Hello ArenMook,

  Static worked, thank you so much.. although I don't understand  why static work... probably my lack of knowledge on c#,  I guess I have a lot to learn...

  Thank you for the help!

  I really appreciate it..

 

3
Hello ArenMook,

 Thanks for your reply,

 I made the variable public

public bool rotate;

public void rotateblock() {
         _block = GetComponent<Block>();
         rotate = true;
         Debug.Log ("Button Pressed");
      

      }


private void UpdateInput()
        {


         if (rotate) {
            rotate = false;
            Debug.Log (rotate);
                  }

}


When pushing the button, nothing happens.

Although the update function does execute once and changes the boolean to False when the script starts.. only once though.. not when the button is clicked.

Thanks,

Seamus

4

   I have a hero with multiple instances, I attached a controller script to the prefab, while the keyboard inputs work fine, when I drag the game object with the controller to the onClick notify part of the button, it executes the function and sets the boolean variable just fine.

   the trouble starts when I try to access the boolen in the update function, it always shows false.. when it is set to true by the onclick function.

   Here's my code.


  using Assets.Scripts.Utils;
using Assets.Scripts.Utils.GameEvents;
using UnityEngine;

namespace Assets.Scripts
{
    public class BlockController : MonoBehaviourBase
    {
      public Sprite[] FaceSprites;
        private Block _block;
        private TimeEvent _nextFallStep;
        private float _lastInputTime;

        private bool rotate;

        public float FallStepDelay;
        public float InputDelay;

        public void Start()
        {
            _block = GetComponent<Block>();
            _nextFallStep = new TimeEvent(FallStepDelay);
        }

        // This is the function in the notify part of onClick in the NGUI button.
        public void rotateHero () {
         
        rotate = true;  // This works it sets it to true.

        }

        public void Update()
        {
            UpdateInput();

            //if (_nextFallStep.PopIsOccurred() && Time.time - _lastInputTime >= InputDelay)
         if (_nextFallStep.PopIsOccurred())
            {
                MoveDown();
                _lastInputTime = Time.time;
            }
        }

        private void UpdateInput()
        {
 
            if (rotate) {

             if (Board.CanRotate(_block))
                    _block.Rotate();
   
              debug.log(rotate);  //Always returns false.. when it should be true.
              rotate = false;

          }
 
            if (Input.GetKeyDown(KeyCode.UpArrow) || Input.GetKeyDown(KeyCode.W))
            {
                if (Board.CanRotate(_block))
                    _block.Rotate();
            }

            if (Time.time - _lastInputTime >= InputDelay)
            {
                if (Input.GetKey(KeyCode.DownArrow) || Input.GetKey(KeyCode.S))
                {
                    MoveDown();
                    _lastInputTime = Time.time;
                }
                else if (Input.GetKey(KeyCode.LeftArrow) || Input.GetKey(KeyCode.A))
                {
                    if (Board.CanMoveLeft(_block))
                    {
                        _block.MoveLeft();
                        _lastInputTime = Time.time;
                    }
                }
                else if (Input.GetKey(KeyCode.RightArrow) || Input.GetKey(KeyCode.D))
                {
                    if (Board.CanMoveRight(_block))
                    {
                        _block.MoveRight();
                        _lastInputTime = Time.time;
                    }
                }   
            }
        }

        private void MoveDown()
        {
            if (Board.CanMoveDown(_block))
                _block.MoveDown();
            else
                FreeBlock();
        }

        private void FreeBlock()
        {
            Destroy(this);
            Board.Place(_block);
        }
    }
}


I hope I am in the right place, maybe I should have asked on the Unity forums?

Thanks,

Seamus

Pages: [1]