Пример #1
0
    public void ReactFireGun(Soldier shooting, GameObject target, TurnManager turnManager)
    {
        int tohit = turnManager.CalculateToHit();
        int roll  = Random.Range(1, 101);

        if (tohit > roll)
        {
            target.GetComponent <Soldier>().TakeDamage(1);

            GameObject clone = Instantiate(turnManager.bulletPrefab2, shooting.transform.position + shooting.transform.forward, transform.rotation) as GameObject;

            clone.GetComponent <Bullet>().holdvel = (target.transform.position - shooting.transform.position) + transform.up;
            uiManager.UpdateScrollingText(shooting.transform.name + ":Hit:" + target.transform.name);
        }
        else
        {
            uiManager.UpdateScrollingText(shooting.transform.name + ":missed:" + target.transform.name);
            //check to see if miss destroys something
            Vector3 newdir = new Vector3(turnManager.lookTarget.transform.position.x + (Random.Range(-0.3f, 1.0f)), turnManager.lookTarget.transform.position.y + (Random.Range(-0.3f, 1.0f)), turnManager.lookTarget.transform.position.z + (Random.Range(-0.3f, 1.0f))) - turnManager.gun.transform.position;

            RaycastHit hit;
            GameObject clone = Instantiate(turnManager.bulletPrefab, turnManager.gun.transform.position, transform.rotation) as GameObject;

            clone.GetComponent <Bullet>().holdvel = newdir;
            if (Physics.Raycast(shooting.transform.position + shooting.transform.forward, newdir, out hit, 15.0f))
            {
                if (hit.transform.tag == "destructable")
                {
                    //  Destroy(hit.transform.gameObject);
                }
            }
        }
    }
Пример #2
0
    public void FireGun(actionData act, TurnManager turnManager)
    {
        // if (act.target == act.actor) { turnManager.CheckRange(5); turnManager.resultdisplay.text = "looking at self "; Debug.Log("dont shoot im you "); }

        //uiManager.UpdateScrollingText(act.actor.transform.name + " shoots at " + act.target.transform.name);



        // if (act.target.team != act.actor.team)
        // {
        act.actor.transform.LookAt(act.target.transform);
        Debug.Log("Firing  gun ");
        //  turnManager.actionRemaining--;
        turnManager.actionpointstext.text = turnManager.actionRemaining.ToString();

        int tohit = turnManager.CalculateToHit();
        int roll  = Random.Range(1, 101);

        if (tohit > roll)
        {
            act.target.TakeDamage(act.damage + 1);
            // turnManager.lastActionPress = -1;
            GameObject clone = Instantiate(turnManager.bulletPrefab2, act.actor.transform.position + act.actor.transform.forward, transform.rotation) as GameObject;

            clone.GetComponent <Bullet>().holdvel = (act.target.transform.position - act.actor.transform.position);
            turnManager.resultdisplay.text        = " HIT : " + act.target.transform.name + " :hp: " + act.target.currenthp.ToString();
            uiManager.UpdateScrollingText(act.actor.transform.name + " : HIT : " + act.target.transform.name + " :hp: " + act.target.currenthp.ToString());
        }
        else
        {
            Debug.Log("miss: Fire gun ");
            //check to see if miss destroys something
            Vector3 newdir = new Vector3(act.target.transform.position.x + (Random.Range(-0.3f, 1.0f)), act.target.transform.position.y + (Random.Range(-0.3f, 1.0f)), act.target.transform.position.z + (Random.Range(-0.3f, 1.0f))) - act.actor.transform.position;
            turnManager.resultdisplay.text = " ::MISSED:: " + act.target.transform.name;
            RaycastHit hit;
            GameObject clone = Instantiate(turnManager.bulletPrefab, act.actor.transform.position + act.actor.transform.forward, transform.rotation) as GameObject;
            uiManager.UpdateScrollingText(act.actor.transform.name + " ::MISSED:: " + act.target.transform.name);
            clone.GetComponent <Bullet>().holdvel = newdir;
            if (Physics.Raycast(turnManager.gun.transform.position, newdir, out hit, 15.0f))
            {
                if (hit.transform.tag == "destructable")
                {
                    //  Destroy(hit.transform.gameObject);
                }
            }
        }
        // }
        // else { Debug.Log("sameteam"); uiManager.UpdateScrollingText(act.actor.transform.name + " doesnt shoot at " + act.target.transform.name); }
    }