Esempio n. 1
0
 void Update()
 {
     if (health <= 0)
     {
         //loot drop
         for (int i = 0; i < Random.Range(3, 6); i++)
         {
             GameObject insItem = Instantiate(playerInventoryScript.droppedItemPrefab, new Vector3(Random.Range(transform.position.x - 1, transform.position.x + 1), -0.7f, Random.Range(transform.position.z - 1, transform.position.z + 1)), playerInventoryScript.droppedItemPrefab.transform.rotation) as GameObject;
             insItem.transform.GetChild(0).GetComponent <DroppedItemScript> ().myValue = new InventoryItem(1, "rocks", "Rocks");
             playerInventoryScript.addDroppedItemToSaves(insItem);
         }
         for (int i = 0; i < Random.Range(1, 3); i++)
         {
             GameObject insItem = Instantiate(playerInventoryScript.droppedItemPrefab, new Vector3(Random.Range(transform.position.x - 1, transform.position.x + 1), -0.7f, Random.Range(transform.position.z - 1, transform.position.z + 1)), playerInventoryScript.droppedItemPrefab.transform.rotation) as GameObject;
             insItem.transform.GetChild(0).GetComponent <DroppedItemScript> ().myValue = new InventoryItem(1, "flint", "Flint");
             playerInventoryScript.addDroppedItemToSaves(insItem);
         }
         for (int i = 0; i < Random.Range(0, 2); i++)
         {
             GameObject insItem = Instantiate(playerInventoryScript.droppedItemPrefab, new Vector3(Random.Range(transform.position.x - 1, transform.position.x + 1), -0.7f, Random.Range(transform.position.z - 1, transform.position.z + 1)), playerInventoryScript.droppedItemPrefab.transform.rotation) as GameObject;
             insItem.transform.GetChild(0).GetComponent <DroppedItemScript> ().myValue = new InventoryItem(1, "coal", "Coal");
             playerInventoryScript.addDroppedItemToSaves(insItem);
         }
         Destroy(gameObject);
     }
     else if (tintBoulder)
     {
         healthTintDelay -= Time.deltaTime;
         if (healthTintDelay <= 0)
         {
             tintBoulder = false;
             GetComponent <Renderer> ().material.color = originalMaterialColour;
         }
     }
 }
Esempio n. 2
0
 void Update()
 {
     if (health <= 0)
     {
         GetComponent <BoxCollider> ().enabled = false;
         transform.Rotate(new Vector3(1, 0, 0) * Time.deltaTime * 30, Space.Self);
         deathDelay -= Time.deltaTime;
         if (deathDelay <= 0)
         {
             //loot drop
             for (int i = 0; i < 3; i++)
             {
                 GameObject insItem = Instantiate(playerInventoryScript.droppedItemPrefab, new Vector3(Random.Range(transform.position.x - 1, transform.position.x + 1), -0.7f, Random.Range(transform.position.z - 1, transform.position.z + 1)), playerInventoryScript.droppedItemPrefab.transform.rotation) as GameObject;
                 insItem.transform.GetChild(0).GetComponent <DroppedItemScript> ().myValue = new InventoryItem(1, "wood", "Wood");
                 playerInventoryScript.addDroppedItemToSaves(insItem);
             }
             float rand = Random.Range(0f, 100f);
             if (rand < 3)
             {
                 GameObject insItem = Instantiate(playerInventoryScript.droppedItemPrefab, new Vector3(Random.Range(transform.position.x - 1, transform.position.x + 1), -0.7f, Random.Range(transform.position.z - 1, transform.position.z + 1)), playerInventoryScript.droppedItemPrefab.transform.rotation) as GameObject;
                 insItem.transform.GetChild(0).GetComponent <DroppedItemScript> ().myValue = new InventoryItem(1, "apple", "Apple");
                 playerInventoryScript.addDroppedItemToSaves(insItem);
             }
             else if (rand < 6)
             {
                 GameObject insItem = Instantiate(playerInventoryScript.droppedItemPrefab, new Vector3(Random.Range(transform.position.x - 1, transform.position.x + 1), -0.7f, Random.Range(transform.position.z - 1, transform.position.z + 1)), playerInventoryScript.droppedItemPrefab.transform.rotation) as GameObject;
                 insItem.transform.GetChild(0).GetComponent <DroppedItemScript> ().myValue = new InventoryItem(1, "orange", "Orange");
                 playerInventoryScript.addDroppedItemToSaves(insItem);
             }
             Destroy(gameObject);
         }
     }
     else if (tintTree)
     {
         healthTintDelay -= Time.deltaTime;
         if (healthTintDelay <= 0)
         {
             tintTree = false;
             transform.GetChild(0).GetComponent <Renderer> ().material.color = originalMaterialColour1;
             transform.GetChild(1).GetComponent <Renderer> ().material.color = originalMaterialColour2;
         }
     }
 }
Esempio n. 3
0
    void Awake()
    {
        playerInventoryScript = GameObject.Find("Player").GetComponent <PlayerInventoryScript> ();

        if (PlayerPrefs.GetInt("saveGame") != 1)
        {
            //generate stuff on terrain
            Vector3 offset = transform.position;
            for (float i = -3 + (int)offset.x; i < 4 + (int)offset.x; i += 2)
            {
                for (float j = -3 + (int)offset.z; j < 4 + (int)offset.z; j += 2)
                {
                    float rand = Random.Range(0f, 100f);
                    if (rand < spawnTreesPercentage)
                    {
                        //spawn trees
                        GameObject insItem = Instantiate(playerInventoryScript.findBuildingPrefabWithName("tree"), new Vector3(i, -1, j), Quaternion.identity);
                        playerInventoryScript.addGameObjectToSaves(insItem);
                    }
                    else if (rand < spawnFlintPercentage + spawnTreesPercentage)
                    {
                        //spawn flint
                        GameObject insItem = Instantiate(droppedItemPrefab, new Vector3(i, -0.7f, j), droppedItemPrefab.transform.rotation) as GameObject;
                        insItem.transform.GetChild(0).GetComponent <DroppedItemScript> ().myValue = new InventoryItem(1, "flint", "Flint");
                        playerInventoryScript.addDroppedItemToSaves(insItem);
                    }
                    else if (rand < spawnGrassPercentage + spawnFlintPercentage + spawnTreesPercentage)
                    {
                        //spawn grass
                        GameObject insItem = Instantiate(playerInventoryScript.findBuildingPrefabWithName("grassPatch"), new Vector3(i + Random.Range(-0.5f, 0.5f), 0, j + Random.Range(-0.5f, 0.5f)), Quaternion.identity);
                        playerInventoryScript.addGameObjectToSaves(insItem);
                    }
                    else if (rand < spawnBushPercentage + spawnGrassPercentage + spawnFlintPercentage + spawnTreesPercentage)
                    {
                        //spawn bush
                        GameObject insItem = Instantiate(playerInventoryScript.findBuildingPrefabWithName("bush"), new Vector3(i + Random.Range(-0.5f, 0.5f), 0, j + Random.Range(-0.5f, 0.5f)), Quaternion.identity);
                        playerInventoryScript.addGameObjectToSaves(insItem);
                    }
                    else if (rand < spawnBerryBushPercentage + spawnBushPercentage + spawnGrassPercentage + spawnFlintPercentage + spawnTreesPercentage)
                    {
                        //spawn berry bush
                        GameObject insItem = Instantiate(playerInventoryScript.findBuildingPrefabWithName("berryBush"), new Vector3(i + Random.Range(-0.5f, 0.5f), 0, j + Random.Range(-0.5f, 0.5f)), Quaternion.identity);
                        playerInventoryScript.addGameObjectToSaves(insItem);
                    }
                    else if (rand < spawnBerryBushPercentage + spawnBushPercentage + spawnGrassPercentage + spawnFlintPercentage + spawnTreesPercentage + spawnBoulderPercentage)
                    {
                        //spawn boulder
                        GameObject insItem = Instantiate(playerInventoryScript.findBuildingPrefabWithName("boulder"), new Vector3(i + Random.Range(-0.5f, 0.5f), 0, j + Random.Range(-0.5f, 0.5f)), playerInventoryScript.findBuildingPrefabWithName("boulder").transform.rotation);
                        playerInventoryScript.addGameObjectToSaves(insItem);
                    }
                    else if (rand < spawnBerryBushPercentage + spawnBushPercentage + spawnGrassPercentage + spawnFlintPercentage + spawnTreesPercentage + spawnBoulderPercentage + spawnCarrotPercentage)
                    {
                        //spawn carrot
                        GameObject insItem = Instantiate(playerInventoryScript.findBuildingPrefabWithName("naturalCarrot"), new Vector3(i + Random.Range(-0.5f, 0.5f), -0.9f, j + Random.Range(-0.5f, 0.5f)), playerInventoryScript.findBuildingPrefabWithName("naturalCarrot").transform.rotation);
                        playerInventoryScript.addGameObjectToSaves(insItem);
                    }
                    else if (rand < spawnBerryBushPercentage + spawnBushPercentage + spawnGrassPercentage + spawnFlintPercentage + spawnTreesPercentage + spawnBoulderPercentage + spawnCarrotPercentage + spawnTomatoPercentage)
                    {
                        //spawn tomato
                        GameObject insItem = Instantiate(playerInventoryScript.findBuildingPrefabWithName("naturalTomato"), new Vector3(i + Random.Range(-0.5f, 0.5f), -0.9f, j + Random.Range(-0.5f, 0.5f)), playerInventoryScript.findBuildingPrefabWithName("naturalTomato").transform.rotation);
                        playerInventoryScript.addGameObjectToSaves(insItem);
                    }
                    else if (rand < spawnBerryBushPercentage + spawnBushPercentage + spawnGrassPercentage + spawnFlintPercentage + spawnTreesPercentage + spawnBoulderPercentage + spawnCarrotPercentage + spawnTomatoPercentage + spawnSheepPercentage)
                    {
                        //spawn sheep
                        GameObject insItem = Instantiate(playerInventoryScript.findMobPrefabWithName("sheep"), new Vector3(i, -0.2f, j), Quaternion.identity);
                        playerInventoryScript.addMobToSaves(insItem);
                    }
                    else if (rand < spawnBerryBushPercentage + spawnBushPercentage + spawnGrassPercentage + spawnFlintPercentage + spawnTreesPercentage + spawnBoulderPercentage + spawnCarrotPercentage + spawnTomatoPercentage + spawnSheepPercentage + spawnPigPercentage)
                    {
                        //spawn pig
                        GameObject insItem = Instantiate(playerInventoryScript.findMobPrefabWithName("pig"), new Vector3(i, -0.2f, j), Quaternion.identity);
                        playerInventoryScript.addMobToSaves(insItem);
                    }
                }
            }
        }
    }
    public void customUpdate()
    {
        if (health <= 0)
        {
            GetComponent <Rigidbody> ().useGravity = false;
            foreach (BoxCollider i in GetComponents <BoxCollider>())
            {
                i.enabled = false;
            }
            transform.Rotate(new Vector3(0, 0, 60) * Time.deltaTime, Space.Self);
            deathDelay -= Time.deltaTime;
            if (deathDelay <= 0)
            {
                //loot drop
                for (int i = 0; i < Random.Range(2, 4); i++)
                {
                    GameObject insItem = Instantiate(playerInventoryScript.droppedItemPrefab, new Vector3(Random.Range(transform.position.x - 1, transform.position.x + 1), -0.7f, Random.Range(transform.position.z - 1, transform.position.z + 1)), playerInventoryScript.droppedItemPrefab.transform.rotation) as GameObject;
                    insItem.transform.GetChild(0).GetComponent <DroppedItemScript> ().myValue = new InventoryItem(1, "meat", "Meat");
                    playerInventoryScript.addDroppedItemToSaves(insItem);
                }
                Destroy(gameObject);
            }
        }
        else if (knockbackDelay > 0)
        {
            knockbackDelay -= Time.deltaTime;
            transform.LookAt(new Vector3(player.transform.position.x, transform.position.y, player.transform.position.z));
            transform.Translate(new Vector3(0, 0.4f, -1) * Time.deltaTime * 10, Space.Self);
            transform.rotation = originalRotation;
        }
        else if (Vector3.Distance(transform.position, player.transform.position) < 40 && health > 0)
        {
            if (!attacked)
            {
                if (moveCountdown > 0)
                {
                    moving         = true;
                    moveCountdown -= Time.deltaTime;
                    transform.Translate(Vector3.forward * Time.deltaTime * currentSpeed);
                }
                else if (pauseMoveCountdown > 0)
                {
                    moving              = false;
                    pauseMoveCountdown -= Time.deltaTime;
                }
                else
                {
                    pauseMoveCountdown = Random.Range(1f, 4.3f);
                    moveCountdown      = Random.Range(2, 15f);
                    transform.Rotate(new Vector3(0, Random.Range(0, 360), 0), Space.World);
                }
                currentSpeed = walkSpeed;
            }
            else
            {
                attackedCountdown -= Time.deltaTime;
                if (attackedCountdown < 0)
                {
                    attacked = false;
                }
                currentSpeed = runSpeed;
                moving       = true;
                transform.LookAt(new Vector3(player.transform.position.x, transform.position.y, player.transform.position.z));
                transform.Rotate(new Vector3(0, 180, 0));
                transform.Translate(Vector3.forward * Time.deltaTime * currentSpeed);
            }

            if (moving)
            {
                if (rightFrontLeg.transform.eulerAngles.x > 30 && rightFrontLeg.transform.eulerAngles.x < 100 && swingForward)
                {
                    swingForward = false;
                }
                if (((rightFrontLeg.transform.eulerAngles.x < 330 && rightFrontLeg.transform.eulerAngles.x > 200) || rightFrontLeg.transform.eulerAngles.x < -30) && !swingForward)
                {
                    swingForward = true;
                }
                if (swingForward)
                {
                    rightFrontLeg.transform.Rotate(new Vector3(Time.deltaTime * 45 * currentSpeed / walkSpeed, 0, 0), Space.Self);
                    leftFrontLeg.transform.Rotate(new Vector3(Time.deltaTime * -45 * currentSpeed / walkSpeed, 0, 0), Space.Self);
                    rightBackLeg.transform.Rotate(new Vector3(Time.deltaTime * 45 * currentSpeed / walkSpeed, 0, 0), Space.Self);
                    leftBackLeg.transform.Rotate(new Vector3(Time.deltaTime * -45 * currentSpeed / walkSpeed, 0, 0), Space.Self);
                }
                else
                {
                    rightFrontLeg.transform.Rotate(new Vector3(Time.deltaTime * -45 * currentSpeed / walkSpeed, 0, 0), Space.Self);
                    leftFrontLeg.transform.Rotate(new Vector3(Time.deltaTime * 45 * currentSpeed / walkSpeed, 0, 0), Space.Self);
                    rightBackLeg.transform.Rotate(new Vector3(Time.deltaTime * -45 * currentSpeed / walkSpeed, 0, 0), Space.Self);
                    leftBackLeg.transform.Rotate(new Vector3(Time.deltaTime * 45 * currentSpeed / walkSpeed, 0, 0), Space.Self);
                }
            }
            else
            {
                if (rightFrontLeg.transform.eulerAngles.x > 3 && rightFrontLeg.transform.eulerAngles.x < 100)
                {
                    rightFrontLeg.transform.Rotate(new Vector3(Time.deltaTime * -45 * currentSpeed / walkSpeed, 0, 0), Space.Self);
                    leftFrontLeg.transform.Rotate(new Vector3(Time.deltaTime * 45 * currentSpeed / walkSpeed, 0, 0), Space.Self);
                    rightBackLeg.transform.Rotate(new Vector3(Time.deltaTime * -45 * currentSpeed / walkSpeed, 0, 0), Space.Self);
                    leftBackLeg.transform.Rotate(new Vector3(Time.deltaTime * 45 * currentSpeed / walkSpeed, 0, 0), Space.Self);
                }
                else if ((rightFrontLeg.transform.eulerAngles.x < 355 && rightFrontLeg.transform.eulerAngles.x > 200) || rightFrontLeg.transform.eulerAngles.x < -5)
                {
                    rightFrontLeg.transform.Rotate(new Vector3(Time.deltaTime * 45 * currentSpeed / walkSpeed, 0, 0), Space.Self);
                    leftFrontLeg.transform.Rotate(new Vector3(Time.deltaTime * -45 * currentSpeed / walkSpeed, 0, 0), Space.Self);
                    rightBackLeg.transform.Rotate(new Vector3(Time.deltaTime * 45 * currentSpeed / walkSpeed, 0, 0), Space.Self);
                    leftBackLeg.transform.Rotate(new Vector3(Time.deltaTime * -45 * currentSpeed / walkSpeed, 0, 0), Space.Self);
                }
            }
        }
    }