private void Awake()
    {
        levelManager   = GameObject.FindGameObjectWithTag("GameController").GetComponentInChildren <LevelManagerScript>();
        ballistaScript = GetComponentInParent <BallistaScript>();

        price = ballistaScript.repairPrice;
    }
Esempio n. 2
0
 private void Awake()
 {
     levelManager      = GameObject.FindGameObjectWithTag("GameController").GetComponentInChildren <LevelManagerScript>();
     trapManager       = GameObject.FindGameObjectWithTag("GameController").GetComponentInChildren <TrapManagerScript>();
     ballistaScript    = GameObject.FindGameObjectWithTag("Player").GetComponent <BallistaScript>();
     trapButtonScripts = FindObjectsOfType <TrapButtonScript>();
 }
    private void Awake()
    {
        trapManager    = GameObject.FindGameObjectWithTag("GameController").GetComponentInChildren <TrapManagerScript>();
        levelManager   = GameObject.FindGameObjectWithTag("GameController").GetComponentInChildren <LevelManagerScript>();
        uIManager      = GameObject.FindGameObjectWithTag("GameController").GetComponentInChildren <UIManagerScript>();
        ballistaScript = GameObject.FindGameObjectWithTag("Player").GetComponent <BallistaScript>();

        price = trapManager.GetPrice(trapType);

        priceText.text = price.ToString();
    }
    public override void OnStateEnter(Animator animator, AnimatorStateInfo animatorStateInfo, int layerIndex)
    {
        ballista = ballista ?? animator.GetComponentInParent <BallistaScript>();

        isDone = false;
    }
Esempio n. 5
0
    public void SimulateFlight(BallistaScript theBallista)
    {
        Vector3 startPos         = new Vector3(0, 0, 0);
        Vector3 endPos           = new Vector3(0, 0, 0);
        Vector3 moveDelta        = new Vector3(0, 0, 0);
        Vector3 simVelocity      = new Vector3(0, 0, 0);
        Vector3 hitSurfaceNormal = new Vector3(0, 1, 0);
        bool    hitTarget        = false;
        bool    hitGround        = false;


        int sanity = 0;

        if (theReticule == null)
        {
            return;
        }

        if (theBallista != null)
        {
            theBallista.GetSpawnBallPosition(out startPos);
            GetLaunchVelocity(theBallista.localElevationAngle, theBallista.localRotationAngle, out simVelocity);

            //print("StartPos = " + startPos + " simVelocity = " + simVelocity);

            //simulate the flight in 1/5 second increments
            while (!hitTarget && !hitGround)
            {
                DoMotion(startPos, 0.1f, ref simVelocity, out moveDelta);
                DoCollisionDetection(startPos, moveDelta, out endPos,
                                     out hitSurfaceNormal, out hitTarget, out hitGround);

                //set our start position to be equal to the end position and try again
                startPos = endPos;
                //print("simVelocity = " + simVelocity);

                sanity++;
                if (sanity > 1000)
                {
                    break;
                }
            }
        }

        if (hitTarget)
        {
            theReticule.renderer.material = greenReticuleMaterial;
        }
        else
        {
            theReticule.renderer.material = redReticuleMaterial;
        }

        //print("hitTarget - " + hitTarget + " endPos = " + endPos + " sanity = " + sanity);

        //where should the reticule go, and what direction should it face?
        theReticule.newPos = endPos;
        theReticule.newOrientationInEulerAngles = Vector3.zero;
        float angleFromVertical = Vector3.Angle(hitSurfaceNormal, Vector3.up);

        if ((angleFromVertical > 1.0f) && (angleFromVertical < 45.0f))
        {
            //	bit of a hack... I know the orientation of the hill,
            //	so if the reticule is hitting anything other than flat ground,
            //	set it to the orientation of the hill
            theReticule.newOrientationInEulerAngles = theGameManager.theHill.transform.eulerAngles;
        }
    }
Esempio n. 6
0
    public void SimulateFlight(BallistaScript theBallista)
    {
        Vector3 startPos = new Vector3(0,0,0);
        Vector3 endPos = new Vector3(0,0,0);
        Vector3 moveDelta = new Vector3(0,0,0);
        Vector3 simVelocity = new Vector3(0,0,0);
        Vector3 hitSurfaceNormal = new Vector3(0,1,0);
        bool hitTarget = false;
        bool hitGround = false;

        int sanity = 0;

        if (theReticule == null)
        {
            return;
        }

        if (theBallista != null)
        {
            theBallista.GetSpawnBallPosition(out startPos);
            GetLaunchVelocity(theBallista.localElevationAngle, theBallista.localRotationAngle, out simVelocity);

            //print("StartPos = " + startPos + " simVelocity = " + simVelocity);

            //simulate the flight in 1/5 second increments
            while (!hitTarget && !hitGround)
            {
                DoMotion(startPos, 0.1f, ref simVelocity, out moveDelta);
                DoCollisionDetection(startPos, moveDelta, out endPos,
                                     out hitSurfaceNormal, out hitTarget, out hitGround);

                //set our start position to be equal to the end position and try again
                startPos = endPos;
                //print("simVelocity = " + simVelocity);

                sanity++;
                if (sanity > 1000)
                {
                    break;
                }
            }
        }

        if (hitTarget)
        {
            theReticule.renderer.material = greenReticuleMaterial;
        }
        else
        {
            theReticule.renderer.material = redReticuleMaterial;
        }

        //print("hitTarget - " + hitTarget + " endPos = " + endPos + " sanity = " + sanity);

        //where should the reticule go, and what direction should it face?
        theReticule.newPos = endPos;
        theReticule.newOrientationInEulerAngles = Vector3.zero;
        float angleFromVertical = Vector3.Angle(hitSurfaceNormal, Vector3.up);
        if ((angleFromVertical > 1.0f) && (angleFromVertical < 45.0f))
        {
            //	bit of a hack... I know the orientation of the hill,
            //	so if the reticule is hitting anything other than flat ground,
            //	set it to the orientation of the hill
            theReticule.newOrientationInEulerAngles = theGameManager.theHill.transform.eulerAngles;
        }
    }