hi all~~
I am getting the following message
You are trying to create a MonoBehaviour using the 'new' keyword. This is not allowed.
MonoBehaviours can only be added using AddComponent()
I know what it means… but the problem is that I am not using a Monobehaviour
public class _charBehaviour{
//My Codes goes here
}
and I called it here
public class _troopManager : MonoBehaviour{
_charBehaviour aNewcharBehaviour = new _charBehaviour aNewcharBehaviour();
}
and _troopManager is attached to a gameobejct in scene
Did I miss something there ?
It seems fine, except the line
_charBehaviour aNewcharBehaviour = new _charBehaviour aNewcharBehaviour();
should be
_charBehaviour aNewcharBehaviour = new _charBehaviour();
nikolic:
It seems fine, except the line
_charBehaviour aNewcharBehaviour = new _charBehaviour aNewcharBehaviour();
should be
_charBehaviour aNewcharBehaviour = new _charBehaviour();
Sorry, that was a typo on my side.
My actual code is exactly the same as what you worite.
This is really bugging me now~~ I am not sure what I did wrong.
Edit: Gah, misread that myself. Silly!
My suggestion is to check that the class you’re instantiating doesn’t inherit from a MonoBehaviour or create one internally, either directly or indirectly. If you’re creating anything provided by Unity, make sure that doesn’t inherit from MonoBehaviour, and so on.
angrypenguin:
Edit: Gah, misread that myself. Silly!
My suggestion is to check that the class you’re instantiating doesn’t inherit from a MonoBehaviour or create one internally, either directly or indirectly. If you’re creating anything provided by Unity, make sure that doesn’t inherit from MonoBehaviour, and so on.
Found itthank you
I did call a MonoBehaviour script from my script. Now it is going well
Thank you