Exemplo n.º 1
0
    // Called every frame
    protected virtual void Update()
    {
        // Make sure the camera exists
        Camera = VA_Helper.GetCamera(Camera);

        if (Camera != null && Prefabs != null)
        {
            // The required key is down?
            if (Input.GetKeyDown(Requires) == true)
            {
                // Find the ray for this screen position
                var ray      = Camera.ScreenPointToRay(Input.mousePosition);
                var rotation = Quaternion.LookRotation(ray.direction);

                // Loop through all prefabs and spawn them
                for (var i = Prefabs.Count - 1; i >= 0; i--)
                {
                    var prefab = Prefabs[i];

                    if (prefab != null)
                    {
                        var clone = (GameObject)Instantiate(prefab, ray.origin, rotation);

                        // Throw with velocity?
                        var cloneRigidbody = clone.GetComponent <Rigidbody>();

                        if (cloneRigidbody != null)
                        {
                            cloneRigidbody.velocity = clone.transform.forward * Speed;
                        }
                    }
                }
            }
        }
    }