Research & Development for 3D & the Web

Player Script in Unity

by on Apr.23, 2010, under Unity Scripts

Creating a simple Character Script

Great Tutorial – Part 1 here: http://www.3dbuzz.com/vbforum/sv_showvideo.php?v=3593

Overwritable Scripts:

Start() – gets called first

Awake() – gets called right before first update

Update() – gets called every frame

(also all of your onMouseOver/enter/trigger/collision etc..)

This script is a simple component..

——————————

PLAYER.JS

public float PlayerSpeed;

void Start() //this is what happens before anything else.

{

transform.position = vector3(transform.position.x transform.position.y, transform.position.z);

}

void Update()

{

float amountToMove = Input.getAxis(“Horizontal”) * PlayerSpeed * Time.deltaTime;   //using delta time makes the speed the same no matter what system specs player has as now speed is based on time rather than system specs.

transform.Translate(Vector3.right * amountToMove);

}

——————————

:programming, scripts, Unity

Leave a Reply

You must be logged in to post a comment.

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Blogroll

A few highly recommended websites...

Log In