Ejemplo n.º 1
0
    public void Update()
    {
        if (gunState == GunStates.Throwing)
        {
            timer += Time.deltaTime;
            if (timer >= coolDownTime)
            {
                timer    = 0;
                gunState = GunStates.Free;
            }
        }

        if (Input.GetMouseButtonDown(1))
        {
            pressing = false;
            if (carryingObject != null)
            {
                fire = true;
            }
        }

        if (Input.GetMouseButton(0))
        {
            pressing = true;
            if (!laser.enabled)
            {
                laser.enabled = true;
            }
        }
        else if (Input.GetMouseButtonUp(0))
        {
            pressing      = false;
            laser.enabled = false;
        }
    }
Ejemplo n.º 2
0
 public void SetState(GunStates state)
 {
     currentState = state;
     anim.SetInteger("State", (int)state);
     if (currentState == GunStates.Shoot)
     {
         AudioManager.Instance.Play("Gunshot");
     }
     if (currentState == GunStates.Reload)
     {
         AudioManager.Instance.Play("Reload");
     }
 }
Ejemplo n.º 3
0
 public void Start()
 {
     gunState            = GunStates.Free;
     pressing            = false;
     laserSpot           = new Vector3(0, 0, gunRange);
     timer               = 0;
     laser               = gameObject.AddComponent <LineRenderer>();
     laser.material      = new Material(Shader.Find("Particles/Additive"));
     laser.useWorldSpace = false;
     laser.enabled       = false;
     laser.SetPosition(0, laserSpot);
     laser.SetWidth(laserWidth, laserWidth);
     laser.SetColors(laserColor1, laserColor2);
 }
Ejemplo n.º 4
0
 public void Shoot(GunStates state)
 {
     if (state == GunStates.Simple)
     {
         SimpleShoot();
     }
     if (state == GunStates.Double)
     {
         DoubleShoot();
     }
     if (state == GunStates.Multiple)
     {
         MultipleShoot();
     }
     if (state == GunStates.Rifle)
     {
         MultipleShoot();
     }
 }
Ejemplo n.º 5
0
 public void ChangeState(GunStates state)
 {
     if (currentState == GunStates.Simple)
     {
         int nextState = Random.Range(1, 3);
         state = (GunStates)nextState;
     }
     if (currentState == GunStates.Double)
     {
         int nextState = Random.Range(2, 3);
         state = (GunStates)nextState;
     }
     if (currentState == GunStates.Multiple)
     {
         int nextState = Random.Range(0, 1);
         state = (GunStates)nextState;
     }
     if (currentState == GunStates.Rifle)
     {
         int nextState = Random.Range(0, 2);
         state = (GunStates)nextState;
     }
     EnterState(state);
 }
Ejemplo n.º 6
0
    public void FixedUpdate()
    {
        if (pressing)
        {
            if (gunState == GunStates.Free)
            {
                RaycastHit hit;
                if (Physics.Raycast(contact.position, contact.forward, out hit, gunRange, movableObjects))
                {
                    gunState = GunStates.Dragging;
                    hit.rigidbody.useGravity = false;
                    carryingObject           = hit.transform.gameObject;
                    SetLaserSopt(Vector3.Distance(hit.point, transform.position));
                }
            }
            else if (gunState == GunStates.Dragging)
            {
                carryingObject.transform.position = Vector3.Lerp(carryingObject.transform.position,
                                                                 contact.position,
                                                                 dragForce * Time.deltaTime);
                Vector3 dir = contact.position - carryingObject.transform.position;

                // TODO: This test to place the object in front of the gun,
                //       only works when every scale has the same length.
                //       Think about a way to work with any scale
                if (dir.magnitude <= carryingObject.transform.localScale.z + 0.5F)
                {
                    gunState = GunStates.Carrying;
                    carryingObject.GetComponent <Rigidbody>().isKinematic = true;
                    carryingObject.GetComponent <Rigidbody>().velocity    = Vector3.zero;
                }

                RaycastHit hit;
                if (Physics.Raycast(contact.position, contact.forward, out hit, gunRange, movableObjects))
                {
                    SetLaserSopt(Vector3.Distance(hit.point, transform.position));
                }
            }
            else if (gunState == GunStates.Carrying)
            {
                carryingObject.transform.position = contact.position + contact.forward * carryingObject.transform.localScale.z * 0.5F;
                carryingObject.transform.rotation = contact.rotation;
                carryingObject.GetComponent <Collider>().isTrigger = true;

                RaycastHit hit;
                if (Physics.Raycast(contact.position, contact.forward, out hit, gunRange, movableObjects))
                {
                    SetLaserSopt(Vector3.Distance(hit.point, transform.position));
                }
            }
        }
        else if (!pressing)
        {
            if (carryingObject != null)
            {
                carryingObject.GetComponent <Rigidbody>().useGravity  = true;
                carryingObject.GetComponent <Rigidbody>().isKinematic = false;
                carryingObject = null;
                carryingObject.GetComponent <Collider>().isTrigger = false;
                gunState = GunStates.Free;
                SetLaserSopt(gunRange);
            }
        }

        if (fire && carryingObject != null)
        {
            fire     = false;
            gunState = GunStates.Throwing;
            timer    = 0;
            carryingObject.GetComponent <Rigidbody>().isKinematic = false;
            carryingObject.GetComponent <Rigidbody>().useGravity  = true;
            carryingObject.GetComponent <Collider>().isTrigger    = true;
            carryingObject.GetComponent <Rigidbody>().AddForce(contact.forward * throwForce);
            carryingObject.GetComponent <Collider>().isTrigger = false;
            carryingObject = null;
            SetLaserSopt(gunRange);
        }
    }
Ejemplo n.º 7
0
 private void EnterState(GunStates state)
 {
     currentState = state;
 }