HI, first check using code tags then I would recommend posting this kind of problems under the scripting forum.
As for the answer, you were already using a timer so you could use that instead of a coroutine to turn off the shield.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Shield1: MonoBehaviour {
public UpgradesPowerups upGradeMagnet;
public AudioSource PowerUPS;
public GameObject shield;
public float Timeleft;
public Image SHIELDIMG ;
void start(){
}
void Update(){
PowerUPS.volume = PlayerPrefs.GetFloat ("SoundFx");
if(stats.onShield)
{
if (Timeleft > 0)
{
Timeleft -= Time.deltaTime;
SHIELDIMG.fillAmount = Timeleft / upGradeMagnet.shieldDuration;
Time.timeScale = 0;
}
else
{
Debug.Log("shieldfalse");
stats.onShield = false;
}
}
public void OnTriggerEnter (Collider Shields)
{
Debug.Log("shield");
if (Shields.CompareTag ("Player"))
{
Pickup (Shields);
}
}
void Pickup(Collider player){
GetComponent<BoxCollider> ().enabled = false;
Debug.Log("shieldTrue");
Timeleft = upGradeMagnet.shieldDuration; //= image indicator
PlayerMotor2 stats = player.GetComponent<PlayerMotor2>();
stats.onShield = true; //
shield.transform.localScale = new Vector3(1, 0, 0);
}
}