Пример #1
0
    //initialize all needed variables,
    //and let the camera fly to the current tower position
    public void Initialize(GameObject guiObj, GameObject crosshair, GameObject aimIndicator,
                           float towerHeight, bool mobile)
    {
        //get scene main camera
        cam = Camera.main.transform;
        //set GUI gameobject passed in
        this.guiObj = guiObj;

        //recognized this application as non-mobile
        //set camera script desktop version
        if (!mobile)
        {
            //get camera control script of main camera
            camDesktop = cam.GetComponent <CameraControl>();
            //disable control script, so all standard movement is disabled
            //(we only want to rotate around while controlling our tower)
            camDesktop.enabled = false;
        }

        //get TowerBase.cs of tower we control (this gameobject)
        towerScript = gameObject.GetComponent <TowerBase>();
        //enable range indicator so it is always visible
        towerScript.rangeInd.renderer.enabled = true;
        //disable tower intelligence, since we want to self control this tower
        towerScript.CancelInvoke("CheckRange");

        //set current tower upgrade level through TowerBase.cs -> Upgrade.cs
        //(we cache them, so we don't need to call this every time in the functions below)
        curLvl = towerScript.upgrade.curLvl;
        //calculate next shot time in the future: last shot game time + delay
        shotTime = towerScript.lastShot + towerScript.upgrade.options[curLvl].shootDelay;
        //also cache attackable enemy type
        enemyType = towerScript.myTargets;

        //TowerRotate of TowerBase.cs is set: we have a turret that rotates
        if (towerScript.turret)
        {
            //get TowerRotation component and disable it:
            //our turret does not follow nearby enemies anymore
            //(we want our turret to follow our mouse/touch input.)
            towerRotScript         = towerScript.turret.GetComponent <TowerRotation>();
            towerRotScript.enabled = false;
        }

        //set crosshair transform reference, since GUILogic.cs instantiated this prefab already
        cross = crosshair.transform;
        //set crosshair positioning behaviour
        centerCrosshair = mobile;

        //get LineRenderer component of the prefab instantiated by GameGUI.cs
        aimRend = aimIndicator.GetComponent <LineRenderer>();
        //set start and end position of LineRenderer
        //[0] = start position, [1] = end position, at first we initialize both to towers shoot position
        aimRend.SetPosition(0, towerScript.shotPos.position);
        aimRend.SetPosition(1, towerScript.shotPos.position);

        //move the camera to our controlled tower position
        Holoville.HOTween.HOTween.To(cam, 1f, "position", transform.position + new Vector3(0, towerHeight, 0), false, Holoville.HOTween.EaseType.EaseInOutExpo, 0f);
        //we don't want to move our crosshair until iTween's animation is completed and the camera reached its destination
        //StartCoroutine() doesn't support delay - and Invoke() doesn't support starting a coroutine
        //so we need to invoke another function in 1 second which then starts the coroutine
        Invoke("StartCoroutineUpdate", 1);
    }
Пример #2
0
    //initialize all needed variables,
    //and let the camera fly to the current tower position
    public void Initialize(GameObject guiObj, GameObject crosshair, GameObject aimIndicator,
                           float towerHeight, bool mobile)
    {
        //get scene main camera
        cam = Camera.main.transform;
        //set GUI gameobject passed in
        this.guiObj = guiObj;

        //recognized this application as non-mobile
        //set camera script desktop version
        if (!mobile)
        {
            //get camera control script of main camera
            camDesktop = cam.GetComponent<CameraControl>();
            //disable control script, so all standard movement is disabled
            //(we only want to rotate around while controlling our tower)
            camDesktop.enabled = false;
        }

        //get TowerBase.cs of tower we control (this gameobject)
        towerScript = gameObject.GetComponent<TowerBase>();
        //enable range indicator so it is always visible
        towerScript.rangeInd.renderer.enabled = true;
        //disable tower intelligence, since we want to self control this tower
        towerScript.CancelInvoke("CheckRange");

        //set current tower upgrade level through TowerBase.cs -> Upgrade.cs
        //(we cache them, so we don't need to call this every time in the functions below)
        curLvl = towerScript.upgrade.curLvl;
        //calculate next shot time in the future: last shot game time + delay
        shotTime = towerScript.lastShot + towerScript.upgrade.options[curLvl].shootDelay;
        //also cache attackable enemy type
        enemyType = towerScript.myTargets;

        //TowerRotate of TowerBase.cs is set: we have a turret that rotates
        if (towerScript.turret)
        {
            //get TowerRotation component and disable it:
            //our turret does not follow nearby enemies anymore
            //(we want our turret to follow our mouse/touch input.)
            towerRotScript = towerScript.turret.GetComponent<TowerRotation>();
            towerRotScript.enabled = false;
        }

        //set crosshair transform reference, since GUILogic.cs instantiated this prefab already
        cross = crosshair.transform;
        //set crosshair positioning behaviour
        centerCrosshair = mobile;

        //get LineRenderer component of the prefab instantiated by GameGUI.cs
        aimRend = aimIndicator.GetComponent<LineRenderer>();
        //set start and end position of LineRenderer
        //[0] = start position, [1] = end position, at first we initialize both to towers shoot position
        aimRend.SetPosition(0, towerScript.shotPos.position);
        aimRend.SetPosition(1, towerScript.shotPos.position);

        //call iTween to move the camera to our controlled tower position
        iTween.MoveTo(cam.gameObject, iTween.Hash("position", transform.position + new Vector3(0, towerHeight, 0), "time", 1, "easetype", iTween.EaseType.easeInOutExpo));
        //we don't want to move our crosshair until iTween's animation is completed and the camera reached its destination
        //StartCoroutine() doesn't support delay - and Invoke() doesn't support starting a coroutine
        //so we need to invoke another function in 1 second which then starts the coroutine
        Invoke("StartCoroutineUpdate", 1);
    }