- Home /
GameObject not working with variable in C# script
I'm very new to Unity, but I've been following a tutorial on YouTube (by Brackeys) to make my first game. In the tutorial, he did 'public Transform player;', which should work as I have seen lots of people do it before. Basically my issue is linking a GameObject to a variable. The Transform component in the main camera doesn't show up in the script but I don't know why. Is anyone able to help solve this..?
Sorry if my terminology isn't right, I'm still very new.
Here is a link to the video: https://www.youtube.com/watch?v=HVB6UVcb3f8 I did exactly what he did, and for the main camera, but Transform isn't showing up for the public variable. (Around 1:35 in the video.)
public class FollowPlayer : MonoBehaviour
{
public Transform player; // This is the part that doesn't work - when I continue it normally changes it to CryptoAPITransform because Transform isn't available.
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
}
Try posting your code (make sure that you tag it correctly - see the FAQ) and include a link to the tutorial, in case your errors are not obvious.
Answer by AaronSxng · Sep 02, 2020 at 08:02 PM
Hey this worked for me. https://www.youtube.com/watch?v=5LX13Xqc50g
Go to Edit -> Preferences -> External Tools -> External Script Editor, and change it to Visual Studios.
Answer by haizathaneefa · Jul 14, 2020 at 06:04 AM
Have you tried changing it to something else other than transform
? GameObject
for example.
I've just tried that, and it doesn't seem to work either. I don't know what I'm doing wrong.
it is imposible the transform gets changed to CryptoAPITransform i bet you already have 2 classes with similar names or something like that, simply crea$$anonymous$$ new cs script and add that line and test it again
try to make a new project and a new scene and try that video out. If it works then something inside of your previous project is causing the error.
Answer by BrewsterBrock · Aug 19, 2020 at 12:57 AM
Update: I tried fixing this by restarting the project a bunch of times, but it still didn't work. In the end, I switched to Brackets instead of Visual Studio and it worked just fine. Hopefully this helps someone.
Your answer
Follow this Question
Related Questions
How to move a Game Object from a script not attached to it. 1 Answer
Cannot place checkpoints position into Transform array 1 Answer
Destroy Gameobject on Collision not working? 3 Answers
problems parenting a gameObject to another upon instantiating when same name exists 1 Answer
Keep adding targets to a list 2 Answers