Hi everybody,
i have written these classes:
Item : Monobehaviour
Abstract Weapon : Item
Gun : Weapon
//Methods that use Coroutine for fire, recoil and others..
public void RechargeGun()
{
StartCoroutine(Recharge());
}
private IEnumerator Recharge()
{
yield return new WaitForSeconds(RechargeTime);
}
This approach is correct?
If i try to instantiate a instance of Gun or Item and i initialize it, for example:
public Gun myGun = new Gun();
When i start the game, a message appear in the console:
You are trying to create a Monobehaviour using the ‘new’ keyboard. This is not allowed. Monobehaviour can only be added using AddComponent(). Alternatively, your script can inherit from ScriptableObject or no base class at all.
It’s not error but this message alert me…
Thanks at all, i need your help.