- Home /
Roll-a-ball tutorial does not work.
I have gone through this tutorial from start to finish, following the instructions exactly. Though the ball moves around, the camera will not follow it, and the camera coordinates in the inspector do not seem to respond to the CameraController script at all.
I am using Unity version 2018.1.0f2
This is the CameraController script I am using (edited in VS 2010):
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraController : MonoBehaviour
{
public GameObject player;
private Vector3 offset;
// Use this for initialization
void Start()
{
//player = GameObject.Find("Player");
offset = transform.position - player.transform.position;
}
// Update is called once per frame
void LateUpdate()
{
//player = GameObject.Find("Player");
transform.position = player.transform.position + offset;
}
}
I have tried some suggested fixes, including the inclusion of the player = GameObject.Find("Player");
but nothing works. I would be very grateful if somebody explain how to make this work, as I have tried every suggestion or alternative code snippet I could find in these forums and elsewhere.
The instructions must either be incomplete, or incompatible with the latest version. It would be nice if Unity could look at this.
Thanks.
Nothing is really jumping out at me at first glance. Can you post the player controller script as well?
Answer by BrilliantOne · May 20, 2018 at 09:32 PM
@pdbarro67 The issue that you are having is that you did not add the Player GameObject to the CameraController script. To do that, go to the Unity editor and select the "Main Camera" object. In the Inspector, look for the Camera Controller Script. If you look at the Camera Controller script, under Player, you will see that there is no object referenced in the Player game object slot. All you have to do now is left-click and drag the Player GameObject from the Hierarchy, and drop it on the Player slot in the Camera Controller script. Hope this solves your issue.
Hi @BrilliantOne,
Thanks very much for the suggestion. I have tried it, however it will not let me drop "Player" from Hierarchy into the Player slot. I get the little "No Entry" cursor saying it can't be dropped there.
I tried the alternate way of using the little dialog accessible from the little button to the right of the Inspector Player field, but get a null list (see picture).
I also tried adding a "Player" Tag to Player in the Inspector. No luck.
Any ideas?
Your answer
Follow this Question
Related Questions
How do I stop my camera rotating with my player? 0 Answers
Roll a Ball Tutorial problem 1 Answer
Unity MMO Controller Example - How to Reposition Camera? 0 Answers
Roll-A-Ball Tutorial: Ball moves on its own 3 Answers
about camera in 2D 3 Answers