Exemple #1
0
    // by callback way
    void OnWandChange(ThreeGlassesWand.Wand pack)
    {
        // you can also get the wand struct info here
        // must bind ThreeGlassesWandBind script

        // it is same as the get version which is in the Update function. just a sample
        if (useType == UseType.UseCallback && inputType == InputType.RightWand)
        {
            float intensity = pack.triggerProcess;
            mat.SetColor("_Color", new Color(intensity, intensity, intensity, 1));
            // create a bullet
            currRate += Time.deltaTime;
            if (currRate > fireRate)
            {
                currRate -= fireRate;


                if (pack.GetKey(InputKey.WandTriggerStrong))
                {
                    GameObject bullet = GameObject.CreatePrimitive((PrimitiveType)bulletType);
                    bullet.transform.position   = firePos.position;
                    bullet.transform.localScale = new Vector3(0.1f, 0.1f, 0.1f);
                    Rigidbody rb = bullet.AddComponent <Rigidbody>();
                    rb.AddForce(transform.forward * bulletSpeed, ForceMode.VelocityChange);
                    Destroy(bullet, 10.0f);
                }
            }
        }
    }