- Home /
Implicit conversion doesn't work with Component. Is it bug?
With this class
using UnityEngine;
using System.Collections;
public class TestCtor
{
string mc;
public TestCtor(string _mc)
{
mc=_mc;
Debug.Log(this==null);
}
public static implicit operator string(TestCtor _ac)
{
return _ac.mc;
}
public static implicit operator TestCtor(string _mc)
{
return new TestCtor(_mc);
}
}
instructions
TestCtor tc="abc"; print(tc);
give me
TestCtor
When I inherit TestCtor from Component, I get
null
When I try to create a MonoBehaviour with new, the compiler throws errors. But it doesn't react to doing the same with Component.
Comment
"When I inherit TestCtor from Component, I get..."
how are you trying to do that?
$$anonymous$$onoBehavoiour
cannot be new'd
I just add : Component
after public class TestCtor
. Component is not $$anonymous$$onoBehaviour
please post some lines of code
Component
after public class TestCtor
. Component is not $$anonymous$$onoBehaviour
makes no sense to me.
Your answer
