LookAtCameraYonly

From Unify Community Wiki
(Difference between revisions)
Jump to: navigation, search
(Description)
m (Reverted edits by Shinriyo (talk) to last revision by NCarter)
 
(10 intermediate revisions by 6 users not shown)
Line 1: Line 1:
 +
[[Category: Camera]]
 +
[[Category: MonoBehaviour]]
 +
[[Category: C Sharp]]
 +
[[Category: Billboard]]
 
Author: Neil Carter (NCarter)
 
Author: Neil Carter (NCarter)
 
==Description==
 
==Description==
This script will rotate a GameObject on its Y axes so that it is always facing the selected camera.  It is useful to make camera facing billboards.
+
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==
 
==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 in the inspector.
+
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==
 
==C# - LookAtCameraYonly.cs==
<csharp>  
+
<syntaxhighlight lang="csharp">  
 
using UnityEngine;
 
using UnityEngine;
 
  using System.Collections;
 
  using System.Collections;
 
    
 
    
  public class LookAtCameraYRotationOnly : MonoBehaviour
+
  public class LookAtCameraYonly : MonoBehaviour
 
  {
 
  {
public Camera cameraToLookAt;
+
    public Camera cameraToLookAt;
 
    
 
    
void Update()  
+
    void Update()  
{
+
    {
Vector3 v = cameraToLookAt.transform.position - transform.position;
+
        Vector3 v = cameraToLookAt.transform.position - transform.position;
v.x = v.z = 0.0f;
+
        v.x = v.z = 0.0f;
transform.LookAt(cameraToLookAt.transform.position - v);  
+
        transform.LookAt(cameraToLookAt.transform.position - v);  
}
+
    }
 
  }
 
  }
</csharp>
+
</syntaxhighlight>
 
+
==Boo - LookAtCameraYonly.boo==
+
<python>
+
</python>
+
 
+
==JavaScript - LookAtCameraYonly.js==
+
<javascript>
+
</javascript>
+

Latest revision as of 17:27, 2 February 2015

Author: Neil Carter (NCarter)

[edit] 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.

[edit] 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.

[edit] C# - LookAtCameraYonly.cs

 
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); 
    }
 }
Personal tools
Namespaces

Variants
Actions
Navigation
Extras
Toolbox