예제 #1
0
 // Update is called once per frame
 void Update()
 {
     if (CC_INPUT.GetButtonDown(wand, WandButton.Menu))
     {
         transform.GetChild(childIndex).gameObject.SetActive(false);
         childIndex = (childIndex + 1) % transform.childCount;
         transform.GetChild(childIndex).gameObject.SetActive(true);
     }
 }
    // Update is called once per frame
    void Update()
    {
        projectile.transform.position = new Vector3(wandTransform.position.x,
                                                    wandTransform.position.y,
                                                    wandTransform.position.z);
        permanentTrail.transform.position = projectile.transform.position;

        if (CC_INPUT.GetButtonDown(wand, WandButton.Trigger))
        {
            GameObject tempProjectile = Instantiate(projectile);
            tempProjectile.AddComponent <DestroyProjectile>();
            tempProjectile.GetComponent <Rigidbody>().isKinematic = false;
            tempProjectile.GetComponent <Rigidbody>().AddForce(CC_CANOE.WandGameObject(wand).transform.forward *projectileForce);
        }
    }
    // Update is called once per frame
    void Update()
    {
        float angle = Mathf.Atan2(CC_INPUT.GetAxis(wand, WandAxis.YAxis), CC_INPUT.GetAxis(wand, WandAxis.XAxis));

        if (angle < 0f)
        {
            angle += 2 * Mathf.PI;
        }

        angle = angle * (180f / Mathf.PI);

        if (CC_INPUT.GetButtonDown(wand, WandButton.TrackpadClick))
        {
            if ((angle >= 45f) && (angle <= 135f))
            {
                Debug.Log("Up object selected");
                chosenParticles = upParticles;
            }
            else if ((angle >= 225f) && (angle <= 315f))
            {
                Debug.Log("Down object selected");
                chosenParticles = downParticles;
            }
            else if ((angle > 135f) && (angle < 225f))
            {
                Debug.Log("Left object selected");
                chosenParticles = leftParticles;
            }
            else if (((angle >= 0) && (angle < 45)) || ((angle > 315) && (angle <= 360f)))
            {
                Debug.Log("Right object selected");
                chosenParticles = rightParticles;
            }
            tempParticles = Instantiate(chosenParticles, wandTransform.position, wandTransform.rotation);
        }
        if (CC_INPUT.GetButtonPress(wand, WandButton.TrackpadClick))
        {
            tempParticles.transform.position = wandTransform.position;
        }

        if (CC_INPUT.GetButtonUp(wand, WandButton.TrackpadClick))
        {
            tempParticles.AddComponent <DestroyProjectile>();
        }
    }
 // Update is called once per frame
 void Update()
 {
     if (CC_INPUT.GetButtonDown(wandToFollow, spawnButton))
     {
         fireballInstance = Instantiate(fireball, null);
     }
     if (CC_INPUT.GetButtonPress(wandToFollow, spawnButton))
     {
         fireballInstance.transform.position = new Vector3(wandTransform.position.x + positionOffset.x,
                                                           wandTransform.position.y + positionOffset.y,
                                                           wandTransform.position.z + positionOffset.z);
         Debug.Log(fireballInstance.transform.position);
     }
     if (CC_INPUT.GetButtonUp(wandToFollow, spawnButton))
     {
         fireballInstance.GetComponent <Rigidbody>().AddForce(wandTransform.forward * launchForce);
         //fireballInstance.GetComponent<DestroyFireball>().enabled = true;
     }
 }
예제 #5
0
    // Update is called once per frame
    void Update()
    {
        //Default color
        Color color = Color.white;

        updateModel();
        updateTrackpad();

        //On the first frame of the click, instantiate a projectile at the position of the trackpad click
        if (CC_INPUT.GetButtonDown(Wand.Left, WandButton.TrackpadClick))
        {
            Debug.Log("trackpad just clicked");
            //Color is calculated using the angle of the click
            color            = new Color(Mathf.Cos(angle), Mathf.Cos(angle + (3 * Mathf.PI / 4)), Mathf.Cos(angle - (3 * Mathf.PI / 4)));
            controlledObject = Instantiate(projectile, new Vector3(x, y + transform.position.y, transform.position.z), Quaternion.identity);
            controlledObject.GetComponent <Renderer>().material.color = color;
            controlledObject.name = "obj_" + projectileIncrement;
            projectileIncrement   = (projectileIncrement + 1) % projectileLimit;
            //When the trackpad is held, the projectile follows the position of the trackpad click and its color is updated
            //to match the new angle
        }
        else if (CC_INPUT.GetButtonPress(Wand.Left, WandButton.TrackpadClick) && (controlledObject != null))
        {
            Debug.Log("trackpad being held");
            controlledObject.transform.position = new Vector3(x, y + transform.position.y, transform.position.z);
            color = new Color(Mathf.Cos(angle), Mathf.Cos(angle + (3 * Mathf.PI / 4)), Mathf.Cos(angle - (3 * Mathf.PI / 4)));
            controlledObject.GetComponent <Renderer>().material.color = color;
            //When the trackpad is released, the force is added to the projectile at the angle it was released at
        }
        else if (CC_INPUT.GetButtonUp(Wand.Left, WandButton.TrackpadClick))
        {
            Debug.Log("trackpad just released");
            //A random z-axis force is applied to the projectile
            float force = (float)forceEnum * forceFactor + forceFactor;
            zForce = CC_CANOE.RandomRange(0f, 1f) * force;
            if (CC_CANOE.RandomRange(0, 1) == 0)
            {
                zForce = -zForce;
            }
            //Force is added to the projectile
            if (controlledObject != null)
            {
                controlledObject.GetComponent <Rigidbody>().AddForce(new Vector3(Mathf.Cos(angle) * force, Mathf.Sin(angle) * force, zForce));
            }
            //If an object of the same name exists, destroy it. This enforces the number of projectiles allowed at once.
            if (GameObject.Find("obj_" + projectileIncrement) != null)
            {
                Destroy(GameObject.Find("obj_" + projectileIncrement));
            }
        }

        if (CC_INPUT.GetButtonDown(Wand.Left, WandButton.Trigger))
        {
            forceEnum = (Force)(((int)(forceEnum) + 1) % System.Enum.GetValues(typeof(Force)).Length);
        }

        if (CC_INPUT.GetButtonDown(Wand.Left, WandButton.Grip))
        {
            modelEnum = (Model)(((int)(modelEnum) + 1) % System.Enum.GetValues(typeof(Model)).Length);
            switch (modelEnum)
            {
            case Model.Orb:
                projectile = orbObject;
                break;

            case Model.Cube:
                projectile = cubeObject;
                break;

            default:
                break;
            }
        }

        //Press the left Menu button to delete all existing projectiles
        if (CC_INPUT.GetButtonDown(Wand.Left, WandButton.Menu))
        {
            for (int i = 0; i < projectileLimit; i++)
            {
                if (GameObject.Find("obj_" + i) != null)
                {
                    Destroy(GameObject.Find("obj_" + i));
                    audioSource.Play();
                }
            }
        }

        toggleInfo.text = "Newly spawned projectiles"
                          + "\nwill be " + modelEnum + "s with " + forceEnum + " force";
    }
    // Update is called once per frame
    void Update()
    {
        Transform wandTransform = CC_CANOE.WandTransform(wand);
        Vector3   offset        = new Vector3(wandTransform.position.x,
                                              wandTransform.position.y + verticalOffset,
                                              wandTransform.position.z);

        float angle = Mathf.Atan2(CC_INPUT.GetAxis(wand, WandAxis.YAxis), CC_INPUT.GetAxis(wand, WandAxis.XAxis));

        if (angle < 0f)
        {
            angle += 2 * Mathf.PI;
        }

        angle = angle * (180f / Mathf.PI);

        if (CC_INPUT.GetButtonDown(wand, WandButton.TrackpadClick))
        {
            if ((angle >= 45f) && (angle <= 135f))
            {
                Debug.Log("Up object selected");
                lanternObj   = upObject;
                chosenButton = WandButton.Up;
            }
            else if ((angle >= 225f) && (angle <= 315f))
            {
                Debug.Log("Down object selected");
                lanternObj   = downObject;
                chosenButton = WandButton.Down;
            }
            else if ((angle > 135f) && (angle < 225f))
            {
                Debug.Log("Left object selected");
                lanternObj   = leftObject;
                chosenButton = WandButton.Left;
            }
            else if (((angle >= 0) && (angle < 45)) || ((angle > 315) && (angle <= 360f)))
            {
                Debug.Log("Right object selected");
                lanternObj   = rightObject;
                chosenButton = WandButton.Right;
            }
        }

        if (CC_INPUT.GetButtonDown(wand, WandButton.TrackpadClick))
        {
            lanternObj.transform.localScale = Vector3.zero;
            Vector3    rotation = lanternObj.transform.eulerAngles;
            Quaternion quat     = Quaternion.identity;
            lantern = Instantiate(lanternObj, offset, quat);
            lantern.gameObject.SetActive(true);
            lantern.transform.position = offset;
        }
        else if (CC_INPUT.GetButtonPress(wand, WandButton.TrackpadClick))
        {
            lantern.transform.position = offset;
        }
        else if (CC_INPUT.GetButtonUp(wand, WandButton.TrackpadClick))
        {
            lantern.GetComponent <Rigidbody>().isKinematic = false;
            lantern.GetComponent <Rigidbody>().AddForce(new Vector3(0, releaseForce, 0));
            lantern.GetComponent <Lantern>().startExpiring = true;
        }
    }