Hi there! I’d like to have a script for camera folowwing a gameobject which is found in this sctipt by tag. Well, I know how to find the GameObject, but I’ve no idea how to create a following camera with first-person view. Help, please!
**I’m using C#, would be nice if you will also use it for the explanation
Awesome! So a bit more of an easy question to start.
Usually in the Answers we won’t just write your code for you.
But I guess I’ll be the exception.
You don’t have to have the actual object scripted to follow the player unless in 3rd person.
You can just drag the Camera as a child to the object itself. But besides that here we go.
This will be the final player instance in which we will use.
GameObject Target;
Now that we have created the variable for the final target we have to go ahead and define the target itself and apply the actual movement of the object.
void Start () {
Target = GameObject.FindWithTag("YourTagName");
transform.parent = Target.transform;
}
Thats really all that you need to do to apply a child. Is change Transform.parent to the parent transform. More info in the Unity Scripting Reference: Unity - Scripting API: Transform.parent