Skip to content
Snippets Groups Projects
PlayerController.cs 3.62 KiB
Newer Older
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
[RequireComponent(typeof(Animator))]
[RequireComponent(typeof(StepBackScript))]
[RequireComponent(typeof(CrossOverScript))]
[RequireComponent(typeof(BehindBackScript))]
[RequireComponent(typeof(MovementScript))]
[RequireComponent(typeof(RoubarBolaScript))]
public class PlayerController : Controller
{
    // Use this for initialization
    void Start ()
    {
        inputs = new Inputs();
        //fazer dinamico
        canMove = true;
        canSkill = true;
        myTurn = true;
        currentHand = 1;        
    private void setup()
        controlType = new KeyBoardControl();
        animatorController = GetComponent<Animator>();
    private void Update()
        inputs.behindBack = Input.GetAxisRaw(controlType.getBehindBackInput());
        inputs.crossOver = Input.GetAxisRaw(controlType.getCrossOverInput());
        inputs.stepBack = Input.GetAxisRaw(controlType.getStepBackInput());
        inputs.horizontalMovement = Input.GetAxisRaw(controlType.getHorizontalInput());
        inputs.verticalMovement = Input.GetAxisRaw(controlType.getVerticalInput());
        inputs.steal = Input.GetAxisRaw(controlType.getStealInput());
        inputs.block = Input.GetAxisRaw(controlType.getBlockInput());
    public override void changeTurn()
            GetComponent<StepBackScript>().enabled = true;
            GetComponent<CrossOverScript>().enabled = true;
            GetComponent<BehindBackScript>().enabled = true;
            GetComponent<MovementScript>().enabled = true;
            FindObjectOfType<ForceBarController>().enabled = true;
            disableBallCollider();
            animatorController.SetTrigger("AtkTurn");
            myTurn = false;
        }
        else
        {
            GetComponent<RoubarBolaScript>().enabled = true;
            GetComponent<MovementScript>().enabled = true;
            GetComponent<BlockScript>().enabled = true;
            enableBallCollider();
            animatorController.SetTrigger("DefTurn");
            myTurn = true;
        }
        //do something
    }
    public virtual void OnDisable()
    {
        GetComponent<StepBackScript>().enabled = false;
        GetComponent<CrossOverScript>().enabled = false;
        GetComponent<BehindBackScript>().enabled = false;
        GetComponent<RoubarBolaScript>().enabled = false;
        GetComponent<MovementScript>().enabled = false;
        GetComponent<BlockScript>().enabled = false;
        
        ForceBarController fbc = FindObjectOfType<ForceBarController>();
        if (fbc != null)
        {
            fbc.enabled = false;
        }
    }

    public void moveToPosition(Transform atkPosition, Transform defPosition)
    {
        if (myTurn)
        {
            GetComponent<MovementScript>().moveToPosition(atkPosition);
        }
        else
        {
            GetComponent<MovementScript>().moveToPosition(defPosition);
        }
    }

    private void disableBallCollider()
    {
        foreach (Transform t in GetComponentInChildren<Transform>())
        {
            if (t.CompareTag("BallCollider"))
            {
                t.GetComponent<BoxCollider2D>().enabled = false;
                return;
            }
        }
    }

    private void enableBallCollider()
    {
        foreach (Transform t in GetComponentInChildren<Transform>())
        {
            if (t.CompareTag("BallCollider"))
            {
                t.GetComponent<BoxCollider2D>().enabled = true;
                return;
            }
        }
    }