Making sprites just rotate and not tilt.

Was checking this script out in order to have my 2D sprites for plants, creatures, and text boxes always face my camera (I have heard there might be a way to do this in the terrain editor or with a shader, but that might be too advanced), however when my character controller looks up or down the sprites are tilting on the Z Axis. I am pretty new, and while I understand some javascript and have been watching tutorials, I am just unclear with this C# one. Thank you very much!

// CameraFacing.cs
// original by Neil Carter (NCarter)
// modified by Hayden Scott-Baron (Dock) - http://starfruitgames.com
// allows specified orientation axis

using UnityEngine;
using System.Collections;

public class CameraFacing : MonoBehaviour
{
Camera referenceCamera;

public enum Axis {up, down, left, right, forward, back};
public bool reverseFace = false; 
public Axis axis = Axis.up; 

// return a direction based upon chosen axis
public Vector3 GetAxis (Axis refAxis)
{
	switch (refAxis)
	{
		case Axis.down:
			return Vector3.down; 
		case Axis.forward:
			return Vector3.forward; 
		case Axis.back:
			return Vector3.back; 
		case Axis.left:
			return Vector3.left; 
		case Axis.right:
			return Vector3.right; 
	}

	// default is Vector3.up
	return Vector3.up; 		
}

void  Awake ()
{
	// if no camera referenced, grab the main camera
	if (!referenceCamera)
		referenceCamera = Camera.main; 
}

void  Update ()
{
	// rotates the object relative to the camera
	Vector3 targetPos = transform.position + referenceCamera.transform.rotation * (reverseFace ? Vector3.forward : Vector3.back) ;
	Vector3 targetOrientation = referenceCamera.transform.rotation * GetAxis(axis);
	transform.LookAt (targetPos, targetOrientation);
}

}

Before that script I was exploring this one, but for some vexing reason my 2D sprites were not oriented in the correct direction (I tried a few different things using empty game objects but I grew frustrated when I couldn’t get it just right).

using System;
using UnityEngine;

public class LookAtTarget : MonoBehaviour
{
public Transform target;

 void Update()
 {
      if(target != null)
      {
           transform.LookAt(target);
      }
 }

}

using UnityEngine;
using System.Collections;

public class lookyHere : MonoBehaviour {

	// Use this for initialization
	public Transform target;
    float lookHeight = 0;
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
	Vector3 tempPos = new Vector3(target.position.x,lookHeight,target.position.z);
    //or use the following line to make sure that the object only looks at its own level
//Vector3 tempPos = new Vector3(target.position.x,transform.position.y,target.position.z);
		
	transform.LookAt(tempPos);
	}
}

something like this may help. you can constrain where something looks at by creating a new vector 3 with the value set at 0 (or any other value). this way the look at wont bother changing that angle

Create a new empty gameObject with the LookAtTarget-script (the bottom one), parent your sprite to it and rotate it such that “forward” is pointing along the blue arrow of the parent gameObject (in local mode). Then, the bottom script should just work fine. It’s far easier to create this kind of hierarchy than to make a complicated script do the compensation.

Which part are you unclear about? Also, is this a billboard thing you want (as in 2D sprites facing a camera in a 3D world, like the original Doom games)? Or are you just trying to get all the sprites to face the camera so the perspective doesn’t make them look not-flat?

If you’re going for a 2D game, make sure you’ve set your camera to be orthographic. Chances are you don’t need perspective, if you’re doing a 2D game (unless you want the 2d Objects to exist in limited 3D space, rather than full 3D space).