hello , im using this script on my camera and im getting a null reference error
using UnityEngine;
using System.Collections;
public class Camera2D : MonoBehaviour {
public Transform player;
public float smoothRate = 0.5f;
private Transform thisTransform;
private Vector2 velocity;
//arxi
void start (){
thisTransform = transform;
velocity = new Vector2(0.5f,0.5f);
}
// Update is called once per frame
void Update () {
Vector2 newPos2D = Vector2.zero;
newPos2D.x = Mathf.SmoothDamp(thisTransform.position.x,player.position.x,ref velocity.x,smoothRate);
newPos2D.y = Mathf.SmoothDamp(thisTransform.position.y,player.position.y,ref velocity.y,smoothRate);
Vector3 newPos = new Vector3(newPos2D.x,newPos2D.y,transform.position.z);
transform.position= Vector3.Slerp(transform.position,newPos,Time.time);
}
}
and also the player using this scrpit cant move horizontaly
using UnityEngine;
using System.Collections;
public class Controller2D : MonoBehaviour {
//Vazw to Character Controller
CharacterController characterController;
//Elenxos varititas
public float gravity = 30;
//movement
public float walkSpeed = 20;
public float jumpHeight = 5;
//Dieuthinsi kinisis
Vector3 moveDirection = Vector3.zero;
float horizontal = 0;
// Otan arixizi to script
void Start () {
characterController = GetComponent<CharacterController>();
horizontal = Input.GetAxis("Horizontal");
}
// Ana frame
void Update () {
//elenxos kinisis pexti
characterController.Move(moveDirection*Time.deltaTime);
//elenxos varititas
moveDirection.y -= gravity * Time.deltaTime;
//kinisi deksia
if(horizontal > 0){
moveDirection.x = horizontal * walkSpeed;
}
//kinisi aristera
if(horizontal < 0){
moveDirection.x = horizontal * walkSpeed;
}
//elenxos jump
if(characterController.isGrounded){
if(Input.GetButtonDown("Jump")){
moveDirection.y = jumpHeight;
}
}
}
}