//private int secondaryWeaponIndex;
    void Awake()
    {
        usableWeapons = gameObject.GetComponent<UsableWeapons> ();

        if(onStartWeaponName != ""){
            primaryWeaponIndex = usableWeapons.primaryUsableWeapons.IndexOf(onStartWeaponName);
            Transform pickupob = Instantiate (usableWeapons.equippedPrimaryUsableWeapons[primaryWeaponIndex], primarySpawnpoint.position, primarySpawnpoint.rotation) as Transform;
            pickupob.parent = transform;
            primaryEquipped = pickupob;
            hasPrimaryWeap = true;
            //pickupob.GetComponent<ShootBullet>().enabled = false; //Use this line while testing to out to prevent enemies from to shooting.
            pickupob.parent.GetComponentInChildren<EnemySight>().equippedWeaponAttackRange = pickupob.GetComponent<weaponIndex>().weaponRange;

        }

        // Else the gameObject needs a random primary weapon at start...
        else{
            //Pick a random weapon from the primary weapon list
            float randomNumber = Random.value*100.0f;
            int usableWeaponCount = usableWeapons.primaryUsableWeapons.Count;
            float minCheck = 0.0f;
            float maxCheck = 0.0f;
            if(randomNumber == 0.0f){
                primaryWeaponIndex = 0;
            }
            else if(randomNumber == 1.0f){
                primaryWeaponIndex = usableWeapons.primaryUsableWeapons.Count - 1;
            }
            else{
                for (int i=0; i < usableWeaponCount; i++){
                    maxCheck = maxCheck + usableWeapons.percentChanceWeaponSpawn[i];
                    if (randomNumber >= minCheck && randomNumber < maxCheck){
                        primaryWeaponIndex = i;
                    }
                    minCheck = maxCheck;
                }
            }

            //Instantiate random weapon and prepare enemy properties
            Transform pickupob = Instantiate (usableWeapons.equippedPrimaryUsableWeapons[primaryWeaponIndex], primarySpawnpoint.position, primarySpawnpoint.rotation) as Transform;
            pickupob.parent = transform;
            primaryEquipped = pickupob;
            hasPrimaryWeap = true;
            //pickupob.GetComponent<ShootBullet>().enabled = false; //Use this line while testing to out to prevent enemies from to shooting.
            pickupob.parent.GetComponentInChildren<EnemySight>().equippedWeaponAttackRange = pickupob.GetComponent<weaponIndex>().weaponRange;

        }
    }
Ejemplo n.º 2
0
    void Start()
    {
        //Define UsableWeapons link:
        gameController = GameObject.FindGameObjectWithTag (Tags.gameController);
        usableWeapons = gameController.GetComponent<UsableWeapons> ();
        playerInfoPanel = GameObject.FindGameObjectWithTag(Tags.canvas).GetComponentInChildren<PlayerInfoPanel> ();
        persistentData = GameObject.FindGameObjectWithTag (Tags.mainCamera).GetComponent<PersistentData> ();

        if(persistentData.primaryWeapon != ""){
            EquipPrimaryWeapon(persistentData.primaryWeapon, persistentData.primaryWeaponAmmoCount, false);
        }
        else{
            if(onStartWeaponName != ""){
                //Determine index of onStartWeaponName
                primaryWeaponIndex = usableWeapons.primaryUsableWeapons.IndexOf(onStartWeaponName);
                Transform pickupob = Instantiate (usableWeapons.equippedPrimaryUsableWeapons[primaryWeaponIndex], primarySpawnpoint.position, primarySpawnpoint.rotation) as Transform;
                pickupob.parent = transform;
                primaryEquipped = pickupob;
                hasPrimaryWeap = true;
                playerInfoPanel.UpdatePrimaryWeaponInfo();

            }
            else{
                Debug.Log ("ERROR: Need to set onStartWeaponName.");
            }
        }
        if(persistentData.secondaryWeapon != ""){
            EquipSecondaryWeapon(persistentData.secondaryWeapon, persistentData.secondaryWeaponAmmoCount, false);
        }
    }
Ejemplo n.º 3
0
    void Update()
    {
        //If the enemy health is <= 0, destroy the enemy
        if(enemyHealth <= 0.0f){
            if(enemyIsAlive){
                if(!cannotDropWeapons){
                    npcWeaponChange = gameObject.GetComponent<NonPlayerCharacterWeaponChange>();

                    dropPoint = npcWeaponChange.dropPoint.position;

                    //Test to see if the dropPoint is being blocked by an obstacle...
                    RaycastHit wallHit;
                    if(Physics.Raycast (transform.position, (dropPoint - transform.position), out wallHit, (dropPoint - transform.position).magnitude, 1 << LayerMask.NameToLayer("Environment_Collision"))){
                        dropPoint = transform.position+(wallHit.point-transform.position)*0.8f;
                    }

                    usableWeapons = gameObject.GetComponent<UsableWeapons>();
                    if(npcWeaponChange.hasPrimaryWeap == true){
                        string equippedWeaponName = npcWeaponChange.primaryEquipped.gameObject.GetComponent<weaponIndex> ().weaponName;
                        int equippedWeaponIndex = usableWeapons.primaryUsableWeapons.IndexOf (equippedWeaponName);
                        dropWeapon = Instantiate(usableWeapons.worldPrimaryUsableWeapons [equippedWeaponIndex], dropPoint, npcWeaponChange.primarySpawnpoint.rotation) as Rigidbody;
                        dropWeapon.AddForce(GetComponent<NavMeshAgent>().velocity*npcWeaponChange.dropForce);
                        dropWeapon.AddTorque (transform.up*npcWeaponChange.dropForce*Random.Range(-0.5f, 0.5f));
                        dropWeapon.GetComponent<weaponIndex>().ammoCount = npcWeaponChange.primaryEquipped.gameObject.GetComponent<weaponIndex> ().ammoCount;
                    }
                    if(npcWeaponChange.hasSecondaryWeap == true){
                        string equippedWeaponName = npcWeaponChange.secondaryEquipped.gameObject.GetComponent<weaponIndex> ().weaponName;
                        int equippedWeaponIndex = usableWeapons.secondaryUsableWeapons.IndexOf (equippedWeaponName);
                        dropWeapon = Instantiate(usableWeapons.worldSecondaryUsableWeapons [equippedWeaponIndex], dropPoint, npcWeaponChange.secondarySpawnpoint.rotation) as Rigidbody;
                        dropWeapon.AddForce(GetComponent<NavMeshAgent>().velocity*npcWeaponChange.dropForce);
                        dropWeapon.AddTorque (transform.up*npcWeaponChange.dropForce*Random.Range(-0.5f, 0.5f));
                        dropWeapon.GetComponent<weaponIndex>().ammoCount = npcWeaponChange.secondaryEquipped.gameObject.GetComponent<weaponIndex> ().ammoCount;
                    }
                }
                if(deadBodyRandomRotation){
                    deadBodyRotation = Quaternion.AngleAxis (Random.Range (0f, 360f),Vector3.up);
                }
                else{
                    deadBodyRotation = transform.rotation;
                }
                deadBody = Instantiate (deadEnemy[damageTypeIndex], transform.position, deadBodyRotation ) as Rigidbody;

                deadBody.transform.Rotate (Vector3.right, 90f);
                if(damageForce!= Vector3.zero){
                    deadBody.AddForce (damageForce);
                }
                if(explosionForce!= 0.0f){
                    //deadBody.AddExplosionForce (explosionForce,explosionLocation, explosionRadius);
                    deadBody.AddForce (explosionForce*((transform.position - explosionLocation).normalized));
                }

                //Pick a random spawnOnDeath from the list
                if(spawnOnDeath.Count > 0){
                    int spawnIndex = 0;
                    float randomNumber = Random.value*100.0f;
                    int spawnOptionCount = spawnOnDeath.Count;
                    float minCheck = 0.0f;
                    float maxCheck = 0.0f;
                    if(randomNumber == 0.0f){
                        spawnIndex = 0;
                    }
                    else if(randomNumber == 1.0f){
                        spawnIndex = spawnOnDeath.Count - 1;
                    }
                    else{
                        for (int i=0; i < spawnOptionCount; i++){
                            maxCheck = maxCheck + percentSpawnOnDeath[i];
                            if (randomNumber >= minCheck && randomNumber < maxCheck){
                                spawnIndex = i;
                            }
                            minCheck = maxCheck;
                        }
                    }
                    Instantiate(spawnOnDeath[spawnIndex], transform.position, spawnOnDeath[spawnIndex].transform.rotation);
                }
                if(targetGO != null){
                    (targetGO.GetComponent(scriptNameToEnable) as MonoBehaviour).enabled = true;
                }
            }
            enemyIsAlive = false;
            /*if(localSceneObjectsExist){
                if(!ignoreEnemyForSceneClearing && gameObject.tag == Tags.enemy && !localScenePersistentGameObjects.isCleared){
                    sceneFadeInOut.remainingEnemiesList.Remove(gameObject);
                    sceneFadeInOut.SceneStatusCheckDelay(true);
                }
            }*/
            if(sceneFadeInOut.remainingEnemiesList.Contains (gameObject)){
                sceneFadeInOut.remainingEnemiesList.Remove(gameObject);
                sceneFadeInOut.SceneStatusCheckDelay(true);
            }
            Destroy(gameObject);

        }
    }
Ejemplo n.º 4
0
    void Update()
    {
        //If the player health is <= 0, destroy the player
        if(playerHealth <= 0.0f){
            if(playerIsAlive){ //Test to see if the player health has just crossed below 0.0

                centerMessageController.UpdateCenterMessage("Press Tab to Restart");
                centerMessageController.FlashCenterMessageAfterSeconds(0.5f);

                playerWeaponChange = playerGO.GetComponent<PlayerWeaponChange>();

                dropPoint = playerWeaponChange.dropPoint.position;
                //Test to see if the dropPoint is being blocked by an obstacle...
                RaycastHit wallHit;
                if(Physics.Raycast (playerWeaponChange.transform.position, (dropPoint - playerWeaponChange.transform.position), out wallHit, (dropPoint - playerWeaponChange.transform.position).magnitude, 1 << LayerMask.NameToLayer("Environment_Collision"))){
                    dropPoint = playerWeaponChange.transform.position+(wallHit.point-playerWeaponChange.transform.position)*0.8f;
                }

                usableWeapons = GameObject.FindGameObjectWithTag(Tags.gameController).GetComponent<UsableWeapons>();

                if(playerWeaponChange.hasPrimaryWeap == true){
                    string equippedWeaponName = playerWeaponChange.primaryEquipped.gameObject.GetComponent<weaponIndex> ().weaponName;
                    int equippedWeaponIndex = usableWeapons.primaryUsableWeapons.IndexOf (equippedWeaponName);
                    dropWeapon = Instantiate(usableWeapons.worldPrimaryUsableWeapons [equippedWeaponIndex], dropPoint, playerWeaponChange.primarySpawnpoint.rotation) as Rigidbody;
                    dropWeapon.AddForce(playerGO.GetComponent<Rigidbody>().velocity*playerWeaponChange.dropForce);
                    dropWeapon.AddTorque (transform.up*playerWeaponChange.dropForce*Random.Range(-0.5f, 0.5f));
                    dropWeapon.GetComponent<weaponIndex>().ammoCount = playerWeaponChange.primaryEquipped.gameObject.GetComponent<weaponIndex> ().ammoCount;
                }
                if(playerWeaponChange.hasSecondaryWeap == true){
                    string equippedWeaponName = playerWeaponChange.secondaryEquipped.gameObject.GetComponent<weaponIndex> ().weaponName;
                    int equippedWeaponIndex = usableWeapons.secondaryUsableWeapons.IndexOf (equippedWeaponName);
                    dropWeapon = Instantiate(usableWeapons.worldSecondaryUsableWeapons [equippedWeaponIndex], dropPoint, playerWeaponChange.secondarySpawnpoint.rotation) as Rigidbody;
                    dropWeapon.AddForce(playerGO.GetComponent<Rigidbody>().velocity*playerWeaponChange.dropForce);
                    dropWeapon.AddTorque (transform.up*playerWeaponChange.dropForce*Random.Range(-0.5f, 0.5f));
                    dropWeapon.GetComponent<weaponIndex>().ammoCount = playerWeaponChange.secondaryEquipped.gameObject.GetComponent<weaponIndex> ().ammoCount;
                }
                deadBody = Instantiate (deadPlayer[damageTypeIndex], playerGO.transform.position, playerWeaponChange.primarySpawnpoint.rotation) as Rigidbody;

                //Check for helmet...
                if(deadBody.GetComponent<Animator>()){
                    Animator[] anims = playerGO.GetComponentsInChildren<Animator> ();
                    Animator deadBodyAnim = deadBody.GetComponent<Animator>();
                    foreach (Animator a in anims) {
                        AnimatorControllerParameter[] acps = a.parameters;
                        foreach (AnimatorControllerParameter acp in acps){
                            if(acp.name == "helmetEquipped"){
                                bool currentValue = a.GetBool ("helmetEquipped");
                                deadBodyAnim.SetBool ("helmetEquipped", currentValue);
                                break;
                            }
                        }
                    }
                    AnimatorControllerParameter[] deadBodyAcp = deadBodyAnim.parameters;
                    AnimatorControllerParameterType paramType = AnimatorControllerParameterType.Bool;
                    int randomIndex = 0;
                    while (paramType != AnimatorControllerParameterType.Trigger){
                        randomIndex = Random.Range (0, deadBodyAcp.Length); //Random.Range is exclusive for the 2nd value
                        paramType = deadBodyAcp[randomIndex].type;
                    }
                    deadBodyAnim.SetTrigger (deadBodyAcp [randomIndex].name);
                }
                //End check for helmet

                if(damageForce != Vector3.zero){
                    deadBody.AddForce (damageForce);
                }
                if(explosionForce != 0.0f){
                    //deadBody.AddExplosionForce(explosionForce, explosionLocation, explosionRadius);
                    deadBody.AddForce (explosionForce*((playerGO.transform.position - explosionLocation).normalized));
                }
            }
            playerIsAlive = false;
            Destroy(playerGO);

        }
    }