Exemplo n.º 1
0
	void Awake ()
	{
		myLife = GetComponent<AgentLife>();
		myMovement = GetComponent<AgentMovement>();

		agent = GetComponent<Agent>();
	}
Exemplo n.º 2
0
	IEnumerator ToxicDamage(AgentLife enemyLife){
		yield return new WaitForSeconds (0.5f);

		for(int i = 0 ; i < toxicDuration ; i++) {
			if (enemyLife == null) {
				yield break;
			}
			enemyLife.TakeDamage (damagePerSecond, Color.green);
			yield return new WaitForSeconds (1f);
		}
	}
    /// <summary>
    /// Méthode d'attaque de l'agent.
    /// </summary>
    protected override AgentLife Attack()
    {
        if(timer < timeBetweenAttacks || myMovement.targets.Count == 0)
        {
            agent.state = Agent.WIGGLE;
            return null;
        }

        myMovement.UpdateList(myMovement.targets);
        GameObject closest = myMovement.GetClosestTarget(myMovement.targets);

        if(closest == null){
            agent.state = Agent.WIGGLE;
            return null;
        }

        if(Vector3.Distance(closest.transform.position, transform.position) > myMovement.stoppingDistance){
            agent.state = Agent.WIGGLE;
            return null;
        }

        AgentLife agentLife = closest.GetComponent<AgentLife>();

        if(agentLife.currentLife > 0 && agentLife.GetComponent<AgentAttack>().enabled && agentLife.GetComponent<AgentMovement>().enabled)
        {
            myMovement.agentRigidbody.velocity = Vector2.zero;
            timer = 0f;

            freezeEnemy = true;
            enemyLife = agentLife;

            FreezeEnemy();

            agent.state = AntibodyAgent.CALL_MACROPHAGE;
        }

        return enemyLife;
    }
    /// <summary>
    /// Permet de dégeler un virus.
    /// </summary>
    void UnfreezeEnemy()
    {
        if(enemyLife == null){
            Destroy(gameObject);
            return;
        }

        AgentMovement enemyMovement = enemyLife.GetComponent<AgentMovement>();
        enemyMovement.enabled = true;
        enemyLife.GetComponent<AgentAttack>().enabled = true;

        enemyLife = null;

        freezeEnemy = false;
        antibodyMovement.hasTarget = false;

        Destroy(gameObject);
    }
    /// <summary>
    /// Permet à l'agent de controler un autre agent.
    /// </summary>
    void ToControl()
    {
        if(target != null){
            if(Vector3.Distance(target.transform.position, transform.position) < 1f){
                cellLife = target.GetComponent<AgentLife>();

                if(cellLife != null){
                    cellLife.currentLife = cellLife.startingLife;
                    cellLife.cellLife.color = Color.blue;
                }

                UpdateLifeCell();

                if(target.name.Contains("Cell"))
                {
                    GameManager.gameManager.GetComponent<ObjectifManager>().updateGoal(7);
                }
                agent.state = VirusAgent.DUPLICATE;
                return;
            }

            Vector3 diff = target.transform.position - transform.position;
            float rot_z = Mathf.Atan2(diff.y, diff.x) * Mathf.Rad2Deg;

            agentRigidbody.rotation = rot_z;
            agentRigidbody.velocity = new Vector2(transform.right.x, transform.right.y) * speed * Time.deltaTime;
        }else{
            GetComponent<AgentLife>().canvas.GetComponent<Canvas>().enabled = true;
            GetComponent<CircleCollider2D>().enabled = true;
            GetComponent<BoxCollider2D>().enabled = true;

            agent.state = Agent.WIGGLE;
            return;
        }
    }
Exemplo n.º 6
0
	// Use this for initialization
	void Start ()
    {
        life = GetComponent<AgentLife>();
	
	}