コード例 #1
0
 //destroys any currently equipped weapon and equips a new weapon
 public void EquipWeapon(GameObject a_weaponToEquip)
 {
     if (EquippedGun != null)
     {
         Destroy(EquippedGun.gameObject);
     }
     else if (EquippedMelee != null)
     {
         Destroy(EquippedMelee.gameObject);
     }
     if (a_weaponToEquip.GetComponent <Melee>() != null)
     {
         EquippedMelee = Instantiate(a_weaponToEquip.GetComponent <Melee>(), WeaponHold) as Melee;
         EquippedMelee.transform.parent = WeaponHold;
         EquippedMelee.SetEntityCollisionLayer(EntityCollisionMask);
         EquippedMelee.SetDestroyableCollisionLayer(m_destroyableCollisionMask);
     }
     else if (a_weaponToEquip.GetComponent <Gun>() != null)
     {
         EquippedGun = Instantiate(a_weaponToEquip.GetComponent <Gun>(), WeaponHold) as Gun;
         EquippedGun.transform.parent = WeaponHold;
         EquippedGun.SetEntityCollisionLayer(EntityCollisionMask);
         EquippedGun.SetEnvironmentCollisionLayer(m_terrainCollisionMask);
     }
 }
コード例 #2
0
 //----------------------------
 #region Actions
 //Instantly reloads the equipped gun with no cool down
 public void InstantReload()
 {
     if (EquippedGun != null)
     {
         EquippedGun.InstantReload();
     }
 }
コード例 #3
0
 private void Awake()
 {
     fpsCamera    = Camera.main;
     equippedGun  = GetComponentInParent <EquippedGun>();
     centerPoint  = new Vector2(Screen.width / 2f, Screen.height / 2f);
     initialAngle = fpsCamera.transform.localEulerAngles;
 }
コード例 #4
0
 public ShootData(GameObject gunObject, EquippedGun gunScript, bool useRecoil, Vector2 centrePoint, Camera fpsCamera)
 {
     this.gunObject   = gunObject;
     this.gunScript   = gunScript;
     this.useRecoil   = useRecoil;
     this.centrePoint = centrePoint;
     this.fpsCamera   = fpsCamera;
 }
コード例 #5
0
    //Attacks with the equipped gun
    public bool Shoot()
    {
        if (EquippedGun != null)
        {
            return(EquippedGun.Shoot());
        }

        return(false);
    }
コード例 #6
0
    //Reloads the equipped gun, returns false if the action failed
    public bool ReloadEquippedGun()
    {
        if (EquippedGun != null)
        {
            return(EquippedGun.ReloadOne());
        }

        return(false);
    }
コード例 #7
0
    public void Awake()
    {
        equippedGun = GetComponent <EquippedGun>();
        if (typeIndex == 1)
        {
            currentGun = allGuns.primaryGuns[gunIndex];
        }
        else
        {
            currentGun = allGuns.secondaryGuns[gunIndex];
        }

        equippedGun.UpdateGun(currentGun);
    }
コード例 #8
0
 //----------------------------
 #region Equippers
 //destroys any currently equipped weapon and equips a new gun
 public void EquipGun(Gun a_gunToEquip)
 {
     if (EquippedGun != null)
     {
         Destroy(EquippedGun.gameObject);
     }
     else if (EquippedMelee != null)
     {
         Destroy(EquippedMelee.gameObject);
     }
     EquippedGun = Instantiate(a_gunToEquip, WeaponHold) as Gun;
     EquippedGun.transform.parent = WeaponHold;
     EquippedGun.SetEntityCollisionLayer(EntityCollisionMask);
     EquippedGun.SetEnvironmentCollisionLayer(m_terrainCollisionMask);
     EquippedGun.SetRicochetCollisionLayer(m_ricochetCollisionMask);
 }
コード例 #9
0
 //Equips a starting weapon
 public void Awake()
 {
     if (m_startingGun != null)
     {
         EquipGun(m_startingGun);
         EquippedGun.SetEntityCollisionLayer(EntityCollisionMask);
         EquippedGun.SetEnvironmentCollisionLayer(m_terrainCollisionMask);
         EquippedGun.SetRicochetCollisionLayer(m_ricochetCollisionMask);
         EquippedGun.SetCurrentClip(m_startingAmmo);
     }
     else if (m_startingMelee != null)
     {
         EquipMelee(m_startingMelee);
         EquippedMelee.SetEntityCollisionLayer(EntityCollisionMask);
         EquippedMelee.SetDestroyableCollisionLayer(m_destroyableCollisionMask);
     }
 }
コード例 #10
0
 private void SelectWeapon(int index)
 {
     if (weaponInstances.Count <= index)
     {
         weaponInstances.Add(InitializeWeapon(Inventory.Weapons[index]));
     }
     selectedGun = weaponInstances[index];
     if (equippedGunMesh != null)
         Destroy(equippedGunMesh.gameObject);
     equippedGunMesh = Utility.InstantiateInParent(selectedGun.EquipGameObject, GunPlaceholder).GetComponent<EquippedGun>();
     if (GameManager.Current != null)
         GameManager.Current.UpdateSwapMessage();
 }
コード例 #11
0
    void Update()
    {
        //topdown behaviour
        if (PlayerBehaviour == Type.TopDown)
        {
            //Move Input
            if (InputDirection == DirectionType.Global)
            {
                moveDirection = new Vector3(Input.GetAxisRaw("Horizontal"), 0f, Input.GetAxisRaw("Vertical")).normalized;
            }
            else
            if (InputDirection == DirectionType.Camera)
            {
                moveDirection        = new Vector3(Input.GetAxisRaw("Horizontal"), 0f, Input.GetAxisRaw("Vertical")).normalized;
                cameraBasedDirection = cam.transform.TransformDirection(moveDirection);
                moveDirection        = new Vector3(cameraBasedDirection.x, moveDirection.y, cameraBasedDirection.z);
            }


            //Aim Input
            float distance;
            Plane aimPlane = new Plane(Vector3.up, Vector3.zero);
            Ray   ray      = cam.ScreenPointToRay(Input.mousePosition);
            if (aimPlane.Raycast(ray, out distance))
            {
                Vector3 hitPoint = ray.origin + ray.direction * distance;
                Debug.DrawLine(cam.transform.position, hitPoint);
                transform.LookAt(new Vector3(hitPoint.x, transform.position.y, hitPoint.z));
            }
        }

        //firstperson behaviour
        if (PlayerBehaviour == Type.FirstPerson)
        {
            EquippedGun.transform.forward = Camera.main.transform.forward;
            //EquippedGun.transform.LookAt(Camera.main.transform.forward * 1000f);
            //Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            //RaycastHit hit;
            //if (Physics.Raycast(ray, out hit, Mathf.Infinity, MaskToIgnore))
            //{
            //    print(":)");
            //    Debug.DrawLine(ray.origin, hit.point);
            //    EquippedGun.transform.LookAt(hit.point);
            //}
        }

        //Shoot Input
        if (Input.GetKeyDown(shootInput) && EquippedGun)
        {
            EquippedGun.Shoot();
        }

        if (moveDirection == Vector3.zero)
        {
            IsMoving = false;
        }
        else
        {
            IsMoving = true;
        }
    }