示例#1
0
    public void Fire(Vector3 position, Vector3 direction, AudioSource audioSource)
    {
        RaycastHit hit;

        //TODO Need to incorporate the accuracy here


        //TODO Maybe i need to used a boxcast of some kind?
        if (Physics.Raycast(position, direction, out hit, range))
        {
            KillableBase killable = hit.transform.GetComponent <KillableBase>();

            //I want to make sure i do negative health (Damage)
            if (killable)
            {
                killable.ChangeHealth(-damage, position);
            }

            //TODO Need some sort of default material to fallback onto
            var temp = hit.transform.GetComponent <Shootable>();
            if (temp)
            {
                temp.Hit(hit);
            }

            //CreateBulletHole(hit.point, hit.normal);
            Debug.DrawLine(position, hit.point, Color.green, 3f);
        }
        else
        {
            Debug.DrawRay(position, direction * range, Color.red, 3f);
        }

        audioSource.PlayOneShot(shootSound);
    }
示例#2
0
    protected override void OnPickedUp(GameObject other)
    {
        KillableBase temp = other.GetComponent <KillableBase>();

        //If the person picking this up can't even use armour, don't try and give them any
        if (temp == null)
        {
            return;
        }

        temp.ChangeHealth(healthAmount);

        base.OnPickedUp(other);
    }
示例#3
0
    private IEnumerator RespawnPlayerCoroutine(KillableBase killable, Vector3 position, Quaternion rotation, float time, bool player)
    {
        if (killable.gameObject.activeInHierarchy == false)
        {
            yield break;
        }



        var o = killable.gameObject;
        var r = o.GetComponent <IRespawnable>();

        if (r == null)
        {
            yield break;
        }

        r.OnDespawn();
        o.SetActive(false);

        if (player)
        {
            float _t = 0f;

            while (_t < time)
            {
                UIManager.Instance.ShowRespawn(true, "Time till respawn " + (int)(time - _t));
                _t += Time.deltaTime;

                yield return(null);
            }
        }
        else
        {
            yield return(new WaitForSeconds(time));
        }


        o.transform.position = position;
        o.transform.rotation = rotation;

        UIManager.Instance.ShowRespawn(false, string.Empty);
        killable.Reset();
        o.SetActive(true);
        r.OnRespawn();
    }
示例#4
0
    ////////////////////////////////////////////////////////////////////////////////////
    ////////////////////////////////////////////////////////////////////////////////////
    ////////////////////////////////////////////////////////////////////////////////////

    //protected string[] AnimationParameters = new string[]
    //{
    //    "Idle",
    //    "Shooting"
    //};

    //protected int[] parameterIds;

    ////////////////////////////////////////////////////////////////////////////////////
    ////////////////////////////////////////////////////////////////////////////////////
    ////////////////////////////////////////////////////////////////////////////////////

    protected override void Init()
    {
        //Set the Animator parameters to their respective Hash Codes
        //parameterIds = new int[AnimationParameters.Length];
        //for (int i = 0; i < AnimationParameters.Length; i++)
        //{
        //    parameterIds[i] = Animator.StringToHash(AnimationParameters[i]);
        //}

        killableBase = GetComponent <KillableBase>();
        killableBase.onHitCallback += Hit;

        //We assign the audio source, and then make sure that its 3D
        audioSource = gameObject.GetComponent <AudioSource>();

        lookMinRotation = Quaternion.Euler(lookMinEuler);
        lookMaxRotaion  = Quaternion.Euler(lookMaxEuler);

        InitState(STATE.IDLE);
    }
示例#5
0
    ////////////////////////////////////////////////////////////////////////////////////
    ////////////////////////////////////////////////////////////////////////////////////
    ////////////////////////////////////////////////////////////////////////////////////

    protected override void Init()
    {
        //Set the Animator parameters to their respective Hash Codes
        parameterIds = new int[AnimationParameters.Length];
        for (int i = 0; i < AnimationParameters.Length; i++)
        {
            parameterIds[i] = Animator.StringToHash(AnimationParameters[i]);
        }

        killableBase = GetComponent <KillableBase>();
        killableBase.onHitCallback += Hit;

        //We assign the audio source, and then make sure that its 3D
        audioSource = gameObject.GetComponent <AudioSource>();

        InitRagdoll();

        SetRagdollGravity(false);

        InitState(STATE.IDLE);
    }
示例#6
0
 public void Respawn(KillableBase killable, Vector3 position, Quaternion rotation, bool isPlayerRespawn)
 {
     StartCoroutine(RespawnPlayerCoroutine(killable, position, rotation, respawnTime, isPlayerRespawn));
 }