Hello guys, right now I’m playing around with unity and have read up alot on GetComponent. I have a Script that inherits from another custom script. The problem is using .getcomponent doesn’t add the needed script to the game object automaticly. So I find my self having to use to add it manual. Is there just a normal limitation of unity with C#? While Reading Forums people using Java have no problem using .GetComponent<>
using UnityEngine;
using System.Collections;
public class TestAiPlayer : NormalAi
{
Country Liyzan;
NormalAi LiyzanPlayerAi;
// Use this for initialization
void Start ()
{
Liyzan = GetComponent<Country>();//works just fine if Country.cs is placed manually
LiyzanPlayerAi = GameObject.Find ("PlayerAI").GetComponent<NormalAi>();//works just fine if NormalAi.cs is placed manually
Liyzan.Init("Liyzan",300000,200,true);
print (string.Format("{0}",Liyzan.Name));
//LiyzanPlayerAi.AiInit(Liyzan);
/**********************************/
}
// Update is called once per frame
void Update ()
{
}
}
Sure I can use .AddComponent(); but I just want to know if this is necessary or am I not using this method correctly. Thanks for the Help Guys