Player Script in Unity
by David 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);
}
——————————

