- Home /
Activate gameobject upon mouseclick
I'm making an rts game. I have a gameobject called 'Unit' Unit has a child object named 'Selected'
Selected is basically just a projector which indicates the unit is selected. But if it is not selected I want the 'Selected' gameobject to be set as inactive. It will be inactive as default. I tried this script to activate it upon mouseclick:
if (hit.collider.transform.FindChild("Selected")) {
if(Input.GetMouseButtonDown(0)) {
Debug.Log ("Found unit");
GameObject selectedObj = hit.collider.Transfrom.FindChild("Selected").gameObject;
selectedObj.SetActive(true);
}
}
But at the fourth line I get the following error:
Assets/Mouse/Mouse.cs(48,79): error CS1061: Type
UnityEngine.Collider' does not contain a definition for
transfrom' and no extension methodtransfrom' of type
UnityEngine.Collider' could be found (are you missing a using directive or an assembly reference?)
If I remove that fourth (and fifth) line, then it works well with the Debug.Log function.
Can anyone help a newbie to understand what this error means?
Answer by Linus · Aug 20, 2013 at 12:17 PM
How does this work:
//Changing Transform to transform
//Transform is the type, transform is the variable
//Also just use .Find
GameObject selectedObj = hit.collider.transform.Find("Selected").gameObject;
Edit: I also noticed that you have a pselling mistake. You spelled it Trans*fr*om
Your answer
![](https://koobas.hobune.stream/wayback/20220613112609im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Cannot select items in Scene window 0 Answers
How to select object with mouse? 3 Answers
Object Selection with large number of objects 1 Answer
Arial camera get selected point 2 Answers