LookAtCameraYonly

From Unify Community Wiki
(Difference between revisions)
Jump to: navigation, search
 
(C# - LookAtCameraYonly.cs)
Line 8: Line 8:
 
==C# - LookAtCameraYonly.cs==
 
==C# - LookAtCameraYonly.cs==
 
<csharp>  
 
<csharp>  
using UnityEngine;
+
using UnityEngine;
 
  using System.Collections;
 
  using System.Collections;
 
    
 
    

Revision as of 21:20, 1 December 2005

Author: Neil Carter (NCarter)

Contents

Description

This script will rotate a billboard or object on its Y axes so that it is always facing the camera, useful for grass billboards etc.

Usage

Place this script on a GameObject that you want to face the camera Then when the object is selected you need to select the Camera you want the object to look at, do this in the inspector.

C# - LookAtCameraYonly.cs

<csharp> using UnityEngine;

using System.Collections;
 
public class LookAtCameraYRotationOnly : MonoBehaviour
{
	public Camera cameraToLookAt;
 
	void Update() 
	{
		Vector3 v = cameraToLookAt.transform.position - transform.position;
		v.x = v.z = 0.0f;
		transform.LookAt(cameraToLookAt.transform.position - v); 
	}
}

</csharp>

Boo - LookAtCameraYonly.boo

<python> </python>

JavaScript - LookAtCameraYonly.js

<javascript> </javascript>

Personal tools
Namespaces

Variants
Actions
Navigation
Extras
Toolbox