Exemplo n.º 1
0
    public void TryInteract()
    {
        if (theOnlyHero == null)
        {
            theOnlyHero = GameObject.FindGameObjectWithTag("Player").GetComponent <HeroesMovement>();
        }
        if (diagUI == null)
        {
            diagUI = GameObject.Find("LocalDataSingleton").transform.GetComponentInChildren <exampleUI>();
        }
        Vector2 choosenOne = GeneralDir == Vector2.zero ? GameObject.FindGameObjectWithTag("Player").GetComponent <HeroesMovement>().directionOfHero : GeneralDir;

        RaycastHit2D rHit = Physics2D.Raycast((Vector2)theOnlyHero.transform.position + choosenOne, choosenOne, 1.0f);

        if (rHit.collider != null)
        {
            //In this example, we will try to interact with any collider the raycast finds
            //Lets grab the NPC's DialogueAssign script... if there's any

            VIDE_Assign assigned;
            if (rHit.collider.GetComponent <VIDE_Assign>() != null)
            {
                assigned = rHit.collider.GetComponent <VIDE_Assign>();
            }
            else
            {
                return;
            }

            if (!diagUI.dialogue.isLoaded)
            {
                //... and use it to begin the conversation
                diagUI.Begin(assigned);
                LocalDataSingleton.instance.talking = true;
            }
            else
            {
                //If conversation already began, let's just progress through it
                diagUI.NextNode();
            }
//#if UNITY_ANDROID
//            if (rHit.collider.GetComponent<minUIExample>() != null && !LocalDataSingleton.instance.talking)
//            {
//                LocalDataSingleton.instance.talking = true;
//                rHit.collider.GetComponent<minUIExample>().dialogue.BeginDialogue(rHit.collider.GetComponent <VIDE_Assign>());
//                Debug.Log("AC");
//            }
//#endif
        }
    }
Exemplo n.º 2
0
 // Use this for initialization
 void Start()
 {
     //BoxCollider2D[] AllTheCollider = GetComponents<BoxCollider2D>();
     //foreach (BoxCollider2D zeBox in AllTheCollider)
     //{
     //    // If the collider isTrigger
     //    if (zeBox.isTrigger)
     //    {
     //        theMeleeAttackCollide = zeBox;
     //        break;
     //    }
     //}
     heroMeleeAnim = GetComponent <HeroAnimateScript>();
     heroMove      = GetComponent <HeroesMovement>();
     soundEffects  = GameObject.FindGameObjectWithTag("AudioManager").GetComponent <SoundEffectsManager>();
 }
Exemplo n.º 3
0
 // Use this for initialization
 void Start()
 {
     soundEffects    = GameObject.FindGameObjectWithTag("AudioManager").GetComponent <SoundEffectsManager>();
     directionOfHero = GetComponent <HeroesMovement>();
     heroAnimator    = GetComponent <HeroAnimateScript>();
 }
Exemplo n.º 4
0
    // Update is called once per frame
    void Update()
    {
        //if (debugginMesh == null)
        //    debugginMesh = GameObject.Find("Remove TODO").GetComponent<TextMesh>(); ;

        if (theOnlyHero == null && ImgFG.IsActive() && ImgBG.IsActive())
        {
            theOnlyHero = GameObject.FindGameObjectWithTag("Player").GetComponent <HeroesMovement>();
        }
        if (fingerHasPressedIt)
        {
            Touch theFingerTouched = Input.GetTouch(theFingerTouchedID);

            switch (theFingerTouched.phase)
            {
            case TouchPhase.Canceled:
                ReturnOrigin();
                return;

            case TouchPhase.Ended:
                ReturnOrigin();
                return;

            default:
                break;
            }

            Vector3 ze3DTouch = new Vector3(theFingerTouched.position.x, theFingerTouched.position.y, ImgBG.rectTransform.position.z);
            directionOfStick = ze3DTouch - ImgBG.rectTransform.position;
            if (directionOfStick.magnitude > Mathf.Abs(ImgBG.rectTransform.sizeDelta.y * 0.5f))
            {
                directionOfStick.Normalize();
                directionOfStick *= Mathf.Abs(ImgBG.rectTransform.sizeDelta.y * 0.5f);
            }
            ImgFG.rectTransform.anchoredPosition = directionOfStick;
            // Since heroes can only move in 4 direction, then we should only do just that!
            // 1st, we will need to check whether it has gone more than a certain threshold!, otherwise stop movement!
            if (directionOfStick.magnitude < ImgBG.rectTransform.sizeDelta.y * 0.25f)
            {
                theOnlyHero.stopMovement();
                movedInXDirection   = 0;
                movedInYDirection   = 0;
                playerPressedButton = false;
                movedInXDirection   = directionOfCurrX = directionOfPrevX = directionOfPrevY = directionOfCurrY = movingInYDirection = 0;
                //debugginMesh.text = "Restart playerPressedButton";
                return; // Otherwise the hero will still be moving!
            }
            if (Mathf.Abs(directionOfStick.x) > Mathf.Abs(directionOfStick.y))
            {
                directionOfStick = new Vector3(directionOfStick.x, 0);
            }
            else
            {
                directionOfStick = new Vector3(0, directionOfStick.y);
            }

            if (directionOfPrevY != directionOfCurrY)
            {
                directionOfPrevY = directionOfCurrY;
            }
            // Below the if statement then it will be recognized in this frame!
            directionOfCurrY   = (short)(Mathf.Clamp(directionOfStick.y, -1.0f, 1.0f));
            movingInYDirection = (short)(directionOfCurrY + directionOfPrevY);
            if (directionOfPrevX != directionOfCurrX)
            {
                directionOfPrevX = directionOfCurrX;
            }
            // Below the if statement then it will be recognized in this frame!
            directionOfCurrX   = (short)(Mathf.Clamp(directionOfStick.x, -1.0f, 1.0f));
            movingInXDirection = (short)(directionOfCurrX + directionOfPrevX);

            // If the player is talking, don't move at all!
            if (LocalDataSingleton.instance.talking)
            {
                return;
            }
            if (!playerPressedButton)
            {
                theOnlyHero.moveDirection(directionOfStick);
            }
            else
            {
                // If player pressed a button and then move the hero in other directions, all will be forgiven.
                if (!(directionOfStick.normalized.x == movedInXDirection && directionOfStick.normalized.y == movedInYDirection))
                {
                    playerPressedButton = false;
                    //debugginMesh.text = "Player moved in other directions: " + movedInXDirection + ", " + movedInYDirection;
                }
                //else
                //{
                //    debugginMesh.text = "Player not moving other directions";
                //}
            }

            //directionOfStick = Input.mousePosition - ImgBG.rectTransform.position;
            //if (directionOfStick.magnitude > Mathf.Abs(ImgBG.rectTransform.sizeDelta.y * 0.5f))
            //{
            //    directionOfStick.Normalize();
            //    directionOfStick *= Mathf.Abs(ImgBG.rectTransform.sizeDelta.y * 0.5f);
            //}
            //ImgFG.rectTransform.anchoredPosition = directionOfStick;
            ////Debug.Log("Direction: " + directionOfStick);
            //// Since heroes can only move in 4 direction, then we should only do just that!
            //// 1st, we will need to check whether it has gone more than a certain threshold!, otherwise stop movement!
            //if (directionOfStick.sqrMagnitude < offsetDistance * offsetDistance)
            //{
            //    theOnlyHero.stopMovement();
            //    return;
            //}
            //if (Mathf.Abs(directionOfStick.x) > Mathf.Abs(directionOfStick.y))
            //{
            //    directionOfStick = new Vector3(directionOfStick.x, 0);
            //}
            //else
            //{
            //    directionOfStick = new Vector3(0, directionOfStick.y);
            //}
            //theOnlyHero.moveDirection(directionOfStick);
        }
        //else if (Input.touchCount > 0)
        //{
        //    Touch[] allZeTouch = Input.touches;
        //    // Check whether any of the finger is at the bottom of the screen!
        //    foreach (Touch zeTouch in allZeTouch)
        //    {
        //        // Checking whether the finger pressed in at the bottom right of the screen and the finger landed on it!
        //        if (zeTouch.position.x < screenSizeX * 0.5f && zeTouch.position.y < screenSizeY * 0.5f && zeTouch.phase == TouchPhase.Began)
        //        {
        //            theFingerTouchedID = zeTouch.fingerId;
        //            ImgFG.gameObject.SetActive(true);
        //            ImgBG.gameObject.SetActive(true);
        //            ImgBG.rectTransform.position = new Vector3(zeTouch.position.x, zeTouch.position.y, ImgBG.rectTransform.position.z);
        //            fingerHasPressedIt = true;
        //            break;
        //        }
        //    }
        //}
        //else
        //{
        //    Debug.Log("Mouse Position: " + Input.mousePosition);
        //    if (Input.mousePosition.x < screenSizeX * 0.25f && Input.mousePosition.y < screenSizeY * 0.25f)
        //    {
        //        fingerHasPressedIt = true;
        //        ImgFG.gameObject.SetActive(true);
        //        ImgBG.gameObject.SetActive(true);
        //        ImgBG.rectTransform.position = Input.mousePosition;
        //        //Debug.Log("Touching bottom right of screen");
        //    }
        //}
    }
Exemplo n.º 5
0
    // Update is called once per frame
    void Update()
    {
        if (theOnlyHero == null && (
                SceneManager.GetActiveScene().buildIndex != 0 &&  //splashpage
                SceneManager.GetActiveScene().buildIndex != 1 &&  //mainmenu
                SceneManager.GetActiveScene().buildIndex != 2 &&  //CUTSCENE_1
                SceneManager.GetActiveScene().buildIndex != 4 &&  //CUTSCENE_2
                SceneManager.GetActiveScene().buildIndex != 10 && //CUTSCENE_3
                SceneManager.GetActiveScene().buildIndex != 11 && //winscreen
                SceneManager.GetActiveScene().buildIndex != 12))  //losescreen
        {
            theOnlyHero = GameObject.FindGameObjectWithTag("Player").GetComponent <HeroesMovement>();
        }
        else if (theOnlyHero != null && (
                     SceneManager.GetActiveScene().buildIndex != 0 &&  //splashpage
                     SceneManager.GetActiveScene().buildIndex != 1 &&  //mainmenu
                     SceneManager.GetActiveScene().buildIndex != 2 &&  //CUTSCENE_1
                     SceneManager.GetActiveScene().buildIndex != 4 &&  //CUTSCENE_2
                     SceneManager.GetActiveScene().buildIndex != 10 && //CUTSCENE_3
                     SceneManager.GetActiveScene().buildIndex != 11 && //winscreen
                     SceneManager.GetActiveScene().buildIndex != 12))  //losescreen
        {
            // Here we shall check which key is pressed so that interception can happen!
            if (!LocalDataSingleton.instance.talking)
            {
                //if (Input.GetKeyDown(KeyCode.UpArrow))
                //    currentKeyPressed = KeyCode.UpArrow;
                //if (Input.GetKeyDown(KeyCode.DownArrow))
                //    currentKeyPressed = KeyCode.DownArrow;
                //if (Input.GetKeyDown(KeyCode.RightArrow))
                //    currentKeyPressed = KeyCode.RightArrow;
                //if (Input.GetKeyDown(KeyCode.LeftArrow))
                //    currentKeyPressed = KeyCode.LeftArrow;
                //if (Input.GetKeyDown(KeyCode.Z))
                //    currentKeyPressed = KeyCode.Z;
                //if (Input.GetKeyDown(KeyCode.X))
                //    currentKeyPressed = KeyCode.X;
                if (Input.GetKeyDown(KeyBindScript.upKey))
                {
                    currentKeyPressed = KeyBindScript.upKey;
                }
                if (Input.GetKeyDown(KeyBindScript.downKey))
                {
                    currentKeyPressed = KeyBindScript.downKey;
                }
                if (Input.GetKeyDown(KeyBindScript.rightKey))
                {
                    currentKeyPressed = KeyBindScript.rightKey;
                }
                if (Input.GetKeyDown(KeyBindScript.leftKey))
                {
                    currentKeyPressed = KeyBindScript.leftKey;
                }
                if (Input.GetKeyDown(KeyBindScript.attackKey))
                {
                    currentKeyPressed = KeyBindScript.attackKey;
                }
                if (Input.GetKeyDown(KeyBindScript.rangeKey))
                {
                    currentKeyPressed = KeyBindScript.rangeKey;
                }
                if (Input.GetKeyDown(KeyBindScript.inventoryKey))
                {
                    currentKeyPressed = KeyBindScript.inventoryKey;
                }

                // Here we check whether the player has continuously press it for movement
                if (Input.GetKey(currentKeyPressed))
                {
                    //switch (currentKeyPressed)
                    //{
                    //    case KeyCode.UpArrow:
                    //        theOnlyHero.moveDirection(new Vector2(0, 1));
                    //        GeneralDir = new Vector2(0, 1);
                    //        break;
                    //    case KeyCode.DownArrow:
                    //        theOnlyHero.moveDirection(new Vector2(0, -1));
                    //        GeneralDir = new Vector2(0, -1);
                    //        break;
                    //    case KeyCode.RightArrow:
                    //        theOnlyHero.moveDirection(new Vector2(1, 0));
                    //        GeneralDir = new Vector2(1, 0);
                    //        break;
                    //    case KeyCode.LeftArrow:
                    //        theOnlyHero.moveDirection(new Vector2(-1, 0));
                    //        GeneralDir = new Vector2(-1, 0);
                    //        break;
                    //    default:
                    //        theOnlyHero.passInKeyPressed(currentKeyPressed);
                    //        //Debug.Log("Something is wrong with current keypressed");
                    //        break;
                    //}
                    if (currentKeyPressed == KeyBindScript.upKey)
                    {
                        theOnlyHero.moveDirection(new Vector2(0, 1));
                        GeneralDir = new Vector2(0, 1);
                    }
                    else if (currentKeyPressed == KeyBindScript.downKey)
                    {
                        theOnlyHero.moveDirection(new Vector2(0, -1));
                        GeneralDir = new Vector2(0, -1);
                    }
                    else if (currentKeyPressed == KeyBindScript.leftKey)
                    {
                        theOnlyHero.moveDirection(new Vector2(-1, 0));
                        GeneralDir = new Vector2(-1, 0);
                    }
                    else if (currentKeyPressed == KeyBindScript.rightKey)
                    {
                        theOnlyHero.moveDirection(new Vector2(1, 0));
                        GeneralDir = new Vector2(1, 0);
                    }
                    else
                    {
                        theOnlyHero.passInKeyPressed(currentKeyPressed);
                    }
                    checkPlayerMoved = true;
                }
            }
        }
    }