void OnTriggerEnter2D(Collider2D other)
        {
            // Something entered the trigger zone!

            HumanBase otherHuman = other.GetComponentInParent <HumanBase>();

            //  If a human came into infection radius, try to infect it.
            if (otherHuman != null)
            {
                HumanBase myHuman = GetComponentInParent <HumanBase>();
                if (myHuman.IsInfectious())
                {
                    // check if myHuman is infectious and if they are in my infection radius
                    float dist    = Vector3.Distance(myHuman.transform.position, otherHuman.transform.position);
                    float r       = 2f * InfectionRadius * transform.parent.localScale.x;
                    float myWidth = myHuman.GetComponent <SpriteRenderer>().bounds.extents.x; //extents = size of width / 2
                    // maybe this is the right infection distance?
                    if (dist < r)
                    {
                        // if I am the player and infected an NPC
                        // this NPC is previously well
                        // I give notice to the level stats
                        if ((myHuman.tag == "Player" || myHuman.wasInfectedByPlayer == true) && otherHuman.IsSusceptible())
                        {
                            // this also adds other human to the list of infected
                            // to count if other human dies later on
                            otherHuman.wasInfectedByPlayer = true;
                            myHuman.levelStats.PlayerInfectedNPC(otherHuman.myID);
                        }

                        otherHuman.Infect();
                    }
                }
            }
        }
        void OnTriggerEnter2D(Collider2D other)
        {
            // Something entered the trigger zone!
            HumanBase otherHuman = other.GetComponentInParent <HumanBase>();

            //  If a human came into infection radius, try to infect it by virus or proganda.
            if (otherHuman != null)
            {
                HumanBase myHuman = GetComponentInParent <HumanBase>();

                // the player is infected by propaganda not neccessarily by the virus, only those with a sign are 100% dangerous, the other only 40%
                if (otherHuman.tag == "Player" && (myHuman.transform.GetChild(1).GetComponent <SpriteRenderer>().enabled == true || UnityEngine.Random.value < 0.4))
                {
                    float dist = Vector3.Distance(myHuman.transform.position, otherHuman.transform.position);
                    float r    = 2f * InfectionRadius * transform.parent.localScale.x;
                    // maybe this is the right infection distance?
                    if (dist < r)
                    {
                        Player player = otherHuman.GetComponentInParent <Player>();
                        // now the player also shows their sign
                        player.transform.GetChild(1).GetComponent <SpriteRenderer>().enabled = true;
                        player.transform.GetChild(2).GetComponent <SpriteRenderer>().enabled = true;
                        player.infectedByPropaganda = true;
                        // notify end level controller
                        LevelSettings.GetActiveEndLevelController().NotifyPlayerInfectedByPropaganda();
                    }
                }

                // maybe also infect with virus
                if (myHuman.IsInfectious())
                {
                    // check if myHuman is infectious and if they are in my infection radius
                    float dist    = Vector3.Distance(myHuman.transform.position, otherHuman.transform.position);
                    float r       = 2f * InfectionRadius * transform.parent.localScale.x;
                    float myWidth = myHuman.GetComponent <SpriteRenderer>().bounds.extents.x; //extents = size of width / 2
                    // maybe this is the right infection distance?
                    if (dist < r)
                    {
                        // if I am the player and infected an NPC
                        // this NPC is previously well
                        // I give notice to the level stats
                        if ((myHuman.tag == "Player" || myHuman.wasInfectedByPlayer == true) && otherHuman.IsSusceptible())
                        {
                            // this also adds other human to the list of infected
                            // to count if other human dies later on
                            otherHuman.wasInfectedByPlayer = true;
                            myHuman.levelStats.PlayerInfectedNPC(otherHuman.myID);
                        }

                        otherHuman.Infect();
                    }
                }
            }
        }
Exemple #3
0
        /// <summary>
        /// Check if player has found us
        /// </summary>
        /// <param name="other"> that which collided with us</param>
        void OnTriggerEnter2D(Collider2D other)
        {
            // Something entered the trigger zone!
            HumanBase otherHuman = other.GetComponentInParent <HumanBase>();

            if (otherHuman != null)
            {
                // Is it really the player?
                if (otherHuman.tag == "Player")
                {
                    // we have been found!
                    friendFound = true;
                    // get the same layer as the player to be able to enter and leave dancefloor
                    // set in project settings
                    gameObject.layer = LayerMask.NameToLayer("Player");
                }
            }
        }
 /// <summary>
 /// Place the human to a certain position on top of everything
 /// and disable all movement and collision
 /// </summary>
 /// <param name="human"> the human to place</param>
 /// <param name="position"> the position of where to place the human</param>
 protected void PlaceAndStopHuman(Vector3 position, Components.HumanBase human)
 {
     //  Removes this human's Rigidbody from the physics simulation,
     //  which disables movement and collision detection.
     human.GetComponent <Rigidbody2D>().simulated = false;
     //  Set the simulated velocity to zero.
     human.GetComponent <Rigidbody2D>().velocity = Vector3.zero;
     // Set position of player hardcoded, see below for how it might
     // work automatically
     human.transform.position = position;
     // make player twice as large
     human.transform.localScale *= 2;
     // make player and every sprite attached to player appear on top of everything
     SpriteRenderer[] renderers = human.transform.GetComponentsInChildren <SpriteRenderer>();
     foreach (SpriteRenderer sr in renderers)
     {
         sr.sortingLayerName = "OnTop";
     }
 }