LookAtCameraYonly

From Unify Community Wiki
(Difference between revisions)
Jump to: navigation, search
(Removing all content from page)
m (Reverted edits by Joseph05408 (Talk); changed back to last version by NCarter)
Line 1: Line 1:
 +
[[Category: Camera]]
 +
[[Category: MonoBehaviour]]
 +
[[Category: C Sharp]]
 +
[[Category: Billboard]]
 +
Author: Neil Carter (NCarter)
 +
==Description==
 +
This script will rotate a GameObject on its Y axis so that it is always facing the selected camera.  It is useful for making camera facing billboards.
  
 +
==Usage==
 +
Place this script on a GameObject that you want to face the camera.  Then, with the object selected, use the inspector to select the Camera you want the object to face.
 +
 +
==C# - LookAtCameraYonly.cs==
 +
<csharp>
 +
using UnityEngine;
 +
using System.Collections;
 +
 
 +
public class LookAtCameraYonly : 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>

Revision as of 19:04, 19 October 2009

Author: Neil Carter (NCarter)

Description

This script will rotate a GameObject on its Y axis so that it is always facing the selected camera. It is useful for making camera facing billboards.

Usage

Place this script on a GameObject that you want to face the camera. Then, with the object selected, use the inspector to select the Camera you want the object to face.

C# - LookAtCameraYonly.cs

<csharp> using UnityEngine;

using System.Collections;
 
public class LookAtCameraYonly : 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>

Personal tools
Namespaces

Variants
Actions
Navigation
Extras
Toolbox