Trying to make a doodle jump replica....how to make the protection shield working???.…. I'm stuck at this point please help me!!

I have made 2D art for shield. I want to instantiate that art for a certain amount of time and at these time I want to disable the monster script which I assigned to monsters. Please help me!!! Or describe another way to do it.@b1gry4n

It would be easier to modify your monster scripts, to only do damage, if the player’s shield is not active. That way, you don’t need to look for all monster scripts, deactivate them, then reactivate them. You only need to look for the player’s script.


You can instantiate something, then destroy it again after a while by using the second parameter in the Destroy method, which defines the delay before an object is destroyed. For example:

GameObject shield = Instantiate(Shield, playerPosition, Quaternion.identity);

// destroys shield after 10 seconds
Destroy(shield ,10f);

Or, you could do something similar with a coroutine, which I recommend, as you can use it to control a bool called, IsShieldActive, which monsters would need to reference, in order to decide whether to do damage or not. For example:

public bool IsShieldActive;

void EnableShield()
{
     IsShieldActive = true;

     GameObject shield = Instantiate(shield, playerPos, Quaternion.identity);
     StartCoroutine(DisableShield(shield, 10f));
}

IEnumerator DisableShield(GameObject Shield, float delay)
{
     yield return new WaitForSeconds(delay);
     Destroy(Shield);

     IsShieldActive = false;
}

@swaparup

@Llama_w_2Ls Sir please do one more help!!!

In my monster script I wrote -
public GameObject player;
public GameObject deadPlayer;

void OnCollisionEnter2D (Collision2D col)
{
     if (relativeVelocity.y <= 0)
     {
         if (col.gameObject.name == "doodler")
         {
              Instantiate (deadPlayer, player.position, player.rotation);
         {
     {
{

Here in this script…How can I check if there the shield is present or not and if it is not then to execute the code… I’m a beginner please help sir…!!!