Question by
Treekiller · Oct 18, 2015 at 09:20 AM ·
c#playerscript.camera-movement
Error in camera script
Hello
I was using a script to make a camera follow a gameobject, but target.transform doesn't work and is marked as an error.
using UnityEngine;
using System.Collections;
public class CameraPlayer : MonoBehaviour {
public GameObject targetl;
public float xOffset = 0;
public float yOffset = 0;
public float zOffset = 0;
void LateUpdate()
{
this.transform.position = new Vector3(target.transform.position.x + xOffset,
target.transform.position.y + yOffset,
target.transform.position.z + zOffset);
}
}
Comment
Answer by Ali-hatem · Oct 18, 2015 at 10:49 AM
using UnityEngine;
using System.Collections;
public class CameraPlayer : MonoBehaviour {
public Transform target1;//attach the gameobject to this script
public float xOffset = 0;
public float yOffset = 0;
public float zOffset = 0;
void LateUpdate()
{
transform.position = new Vector3(target.position.x + xOffset, target.position.y + yOffset, target.position.z + zOffset);
}
}
Your answer
Follow this Question
Related Questions
Game working in pc but not in Android While Testing 0 Answers
How to Parent a Camera to the Head Bone with No Camera Shake? 0 Answers
How do I make somthing happen when the Player reaches a certain x, y, z position? 0 Answers
I have a problem with my Camera detecting and following the player!! pls help... 0 Answers