Skip to main content

Posts

Showing posts from October, 2011

Making A Laser Pointer

Want a frieking lazer pointer?
BOOM.
Attach a Line Renderer component to the object you have the script below attached to. (Component> Miscellaneous>Line Renderer)

Code:
function Update () { var lineRenderer : LineRenderer = GetComponent(LineRenderer); lineRenderer.useWorldSpace = false; lineRenderer.SetVertexCount(2); var hit : RaycastHit; Physics.Raycast(transform.position,transform.forward,hit); if(hit.collider){ lineRenderer.SetPosition(1,Vector3(0,0,hit.distance)); } else{ lineRenderer.SetPosition(1,Vector3(0,0,5000)); } } @script RequireComponent(LineRenderer) Thank 3dDude for the script.
Original Source here.

Limiting Rotation of an Object

I made this script for my Beach Defender Game. It was to keep the player from rotating more than I want his to, because I'm a mean person like that. Any way it took me awhile to figure out how to not make them turn to far to the left, right, up, down.. You know. Here's the script. Pretty simple. Put under Update function. Feel free to suggest different ways. Or ask any questions.


var upDown = Input.GetAxis("Vertical") *Time.deltaTime * (rotateSpeed-10); var leftRight = Input.GetAxis("Horizontal") * Time.deltaTime * (rotateSpeed-10); //making it turn up or down if(transform.localEulerAngles.x < 25 ){ transform.Rotate(upDown, 0, 0); } else if (transform.localEulerAngles.x > 295){ transform.Rotate(upDown, 0, 0); } //making it turn left or right if(transform.localEulerAngles.y < 65 ){ …