示例#1
0
            private void Update()
            {
                NPCMove();

                // El siguiente bloque de código lee la posición de los aldeanos, cuando la distancia es menor al rango, los zombies pasan a perseguirlos.
                Villagers closest         = null;
                float     closestDistance = 5.0f;

                foreach (var v in FindObjectsOfType <Villagers>())
                {
                    float distance = Vector3.Distance(v.transform.position, transform.position);

                    if (distance < closestDistance)
                    {
                        m                   = Move.Pursuing;
                        closest             = v;
                        closestDistance     = distance;
                        direction           = Vector3.Normalize(v.transform.position - transform.position);
                        transform.position += direction * npcSpeed * Time.deltaTime;
                    }
                }

                // El siguiente bloque de código imprime los mensajes cuando el héroe entra en el rango de ataque.
                float zombieAttack = Vector3.Distance(target.position, transform.position);

                if (zombieAttack <= 5.0f && closest == null)
                {
                    StartCoroutine("PrintMessages");
                }
            }
示例#2
0
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.R))
        {
            GameManager.instance.NextLevel();
        }

        if (Input.GetMouseButtonDown(0))
        {
            hitOrigin = Camera.main.ScreenToWorldPoint(Input.mousePosition);
            colliders = Physics2D.OverlapCircleAll(hitOrigin, 0.25f, villagerLayer);

            if (colliders != null)
            {
                Villagers enemy = gameManager.enemyVillager;
                for (int i = 0; i < colliders.Length; i++)
                {
                    if (colliders[i].GetComponent <Villagers>() == enemy)
                    {
                        gameManager.NextLevel();
                    }
                    else
                    {
                        audioSource.clip = incorrectSelectionSound;
                        audioSource.Play();
                        gameManager.IncrementStrikes();
                        colliders[i].GetComponent <Villagers>().BlowUp();
                    }
                }
            }
        }
        movementDirection = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical"));
        movementDirection = movementDirection.normalized;
    }
示例#3
0
    IEnumerator PrintMessages(Villagers villager) // Esta Corutina es la que asigna los mensajes de los ciudadanos.
    {
        Message.text = villager.PrintNames();
        yield return(new WaitForSeconds(3));

        Message.text = "";
    }
示例#4
0
 /// <summary>
 ///  Clean up any resources being used.
 /// </summary>
 /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
 protected override void Dispose(bool disposing)
 {
     if (disposing && (components != null))
     {
         components.Dispose();
         Villagers.Dispose();
     }
     base.Dispose(disposing);
 }
示例#5
0
    IEnumerator PrintMessages(Villagers villager) // Esta Corutina es la que asigna los mensajes de los ciudadanos.
    {
        message.text = villager.Message();
        yield return(new WaitForSeconds(3));

        message.text = "";

        if (Creator.inGame == false)
        {
            message.text = "";
        }
    }
	public Villager findVillagerByVillagerType(VillagerTypes vType)
	{
		Villagers v = new Villagers();
		foreach(Villagers vv in villagers)
		{
			if(vv.vType == vType)
				v = vv;
		}
		if(v != null)
			return v.villager.GetComponent<Villager>();
		else
			return null;
	}
示例#7
0
    public void SaveVillager(Villager villager)
    {
        Villagers.Remove(villager.gameObject);
        vFollowers.Remove(villager.Follower.gameObject);
        Followers.Remove(villager);
        Destroy(villager.Follower.gameObject);
        Destroy(villager.Follower);
        Destroy(villager.gameObject);

        //CreateNewVillager();
        savedVillagers++;
        SavedVillagersText.guiText.text = "Villagers Saved: " + savedVillagers;
    }
	public GameObject findVillagerGameObjectByVillagerType(VillagerTypes vType)
	{
		Villagers v = new Villagers();
		foreach(Villagers vv in villagers)
		{
			if(vv.vType == vType)
				v = vv;
		}
		if(v != null)
			return v.villager;
		else
			return null;
	}
示例#9
0
    void OnEnable()
    {
        // ? Instantiate what needs to be initiated before game start here.
        places    = Instantiate(placesPrefab, placesOrigin.position, Quaternion.identity).GetComponent <Places>();
        villagers = Instantiate(villagersPrefab, villagersOrigin.position, Quaternion.identity).GetComponent <Villagers>();

        // ? Link object between them here.
        gameCanvas.throwDices.onClick.AddListener(new UnityEngine.Events.UnityAction(DicesStep_ThrowDices));
        gameCanvas.nextStep.onClick.AddListener(new UnityEngine.Events.UnityAction(NextStep));
        gameCanvas.eventOption1.onClick.AddListener(new UnityEngine.Events.UnityAction(NextStep));
        gameCanvas.eventOption1.onClick.AddListener(new UnityEngine.Events.UnityAction(() => PickEffect(0)));
        gameCanvas.eventOption2.onClick.AddListener(new UnityEngine.Events.UnityAction(NextStep));
        gameCanvas.eventOption2.onClick.AddListener(new UnityEngine.Events.UnityAction(() => PickEffect(1)));
    }
示例#10
0
    void Start()
    {
        gameManager = GameManager.instance;
        int amount      = gameManager.GetVillagerAmountToSpawn();
        int randomIndex = Random.Range(0, amount);

        for (int i = 0; i < amount; i++)
        {
            Villagers v = Instantiate(villagerPrefab);
            if (i == randomIndex)
            {
                gameManager.enemyVillager = v;
            }
        }
    }
    public VillagerNode CreateVillager(string villagerName, Vector3 position)
    {
        GameObject newVillager = Instantiate(VillageData.villagerPrefab, position, Quaternion.identity);

        UtilityFunctions.PutObjectOnGround(newVillager.transform);

        VillagerNode villagerNode = newVillager.AddComponent <VillagerNode>();

        villagerNode.SetUp(villagerName);
        villagerNode.transform.parent = transform;

        Villagers.Add(villagerNode);
        AddLink(villagerNode);

        return(villagerNode);
    }
示例#12
0
        public IPeople GetPeople(PeopleType type)
        {
            IPeople people = null;

            switch (type)
            {
            case PeopleType.Rural:
                people = new Villagers();
                break;

            case PeopleType.Urban:
                people = new CityPeople();
                break;
            }
            return(people);
        }
示例#13
0
 public IPeople GetPeople(PeopleType type)
 {
     IPeople people = null;
     switch (type)
     {
         case PeopleType.RURAL:
             people = new Villagers();
             break;
         case PeopleType.URBAN:
             people = new CityPeople();
             break;
         default:
             break;
     }
     return people;
 }
示例#14
0
            // La siguiente función lee la posición de los aldeanos, cuando la distancia es menor al rango, los enemigos pasan a perseguirlos.
            public void GetTarget()
            {
                Villagers closest         = null;
                float     closestDistance = 5.0f;

                foreach (var v in FindObjectsOfType <Villagers>())
                {
                    float distance = Vector3.Distance(v.transform.position, transform.position);

                    if (distance < closestDistance)
                    {
                        m                   = Move.Reacting;
                        closest             = v;
                        closestDistance     = distance;
                        direction           = Vector3.Normalize(v.transform.position - transform.position);
                        transform.position += direction * npcSpeed * Time.deltaTime;
                    }
                }
            }
示例#15
0
    public Villager findVillagerByVillagerType(VillagerTypes vType)
    {
        Villagers v = new Villagers();

        foreach (Villagers vv in villagers)
        {
            if (vv.vType == vType)
            {
                v = vv;
            }
        }
        if (v != null)
        {
            return(v.villager.GetComponent <Villager>());
        }
        else
        {
            return(null);
        }
    }
示例#16
0
    public void KillVillager(Villager villager)
    {
        //Debug.Log (villager);
        // Remove the Villager from everything and stuff
        Villagers.Remove(villager.gameObject);
        vFollowers.Remove(villager.Follower.gameObject);
        Followers.Remove(villager);
        Destroy(villager.Follower.gameObject);
        Destroy(villager.Follower);
        Destroy(villager.gameObject);

        // create new villager
        //CreateNewVillager();

        // increment
        deadVillagers++;

        // Update text
        DeadVillagersText.guiText.text = "Villagers Killed: " + deadVillagers;
    }
示例#17
0
    public GameObject findVillagerGameObjectByVillagerType(VillagerTypes vType)
    {
        Villagers v = new Villagers();

        foreach (Villagers vv in villagers)
        {
            if (vv.vType == vType)
            {
                v = vv;
            }
        }
        if (v != null)
        {
            return(v.villager);
        }
        else
        {
            return(null);
        }
    }
示例#18
0
 public void AddVillager(Villager villager)
 {
     Villagers.Add(NbVillagers, villager);
     NbVillagers++;
 }