Reputation: 24112
I am quite new to Unity. I am trying to make a simple script that makes the camera always look at the ship in the scene.
I have:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class LookAt : MonoBehaviour {
public Transform playerShip;
// Update is called once per frame
void Update () {
transform.LookAt(playerShip);
}
}
I have named the target in the scene playerShip but it gives me an error:
Assets/LookAtShip.cs(7,9): error CS0118: `UnityEngine.Component.gameObject' is a `property' but a `type' was expected
Upvotes: 0
Views: 171
Reputation: 101
You must use: transform.LookAt(playerShip.position);
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class LookAt : MonoBehaviour {
public Transform playerShip;
// Update is called once per frame
void Update () {
transform.LookAt(playerShip.position);
}
}
Upvotes: 1