I have this script called abb with the following code
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class abb : MonoBehaviour
{
public GameObject test;
myScript aaa;
void Start()
{
myScript = test.GetComponentsInChildren<aaa> ();
}
}
And codenamed aaa
with the following simple code
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class aaa : MonoBehaviour
{
int a;
void Start()
{
a=1;
}
}
I am trying to be able to see the value of a from script aaa in script abb but all I get is a namespace error. I canât even attach the scripts to Gameobjects.What am I missing?
I have using system.Collections and using Systems.collections.generic greyed out at the top a mouse over reports uneccessary using directive.Using vscode
Assets\match3code\code\abb.cs(8,2): error CS0246: The type or namespace name âmyScriptâ could not be found (are you missing a using directive or an assembly reference?)
No its not supposed to be the other way round.I did it just to see and you get the error
Assets\match3code\code\abb.cs(12,14): error CS0029: Cannot implicitly convert type âaaa[ ]â to âaaaâ
Would you mind loading that code into a empty project and seeing if you get any errors?
Yes I did mean that but it makes no difference to change it,I even tried loading up unity 5 (still the best version imo) and using monodevelop in case it was an error in the vs code editor itself but it throws an error in that as well I donât understand these scripts should work no problemo shouldnât they?.
That may be true when MyScript is a type (class or struct). In the line above you write GameObject test; so the type first and the name of your desired variable last. You do it the other way round and write your variable name âmyScriptâ first and your type âaaaâ last. Thats all Iâm saying.
There is still the chance that Iâm understanding your code or your intentions wrong. I have made my point and am out now. But my advise of proper naming conventions still applies. Good luck.