Learn how to use Python & EcmaScript (JavaScript) to script your Unilarity game.
Python is a supported scripting language in Unilarity, allowing you to interact with the game engine.
import clr clr.AddReference("Unilarity") from Unilarity import * ani = None sr = None rb = None speed = 80 jumpForce = 150 def Awake(): global ani, sr, rb ani = gameObject.GetComponent(SpriteAnimator) sr = gameObject.GetComponent(SpriteRenderer) rb = gameObject.GetComponent(Rigidbody2D) def Update(): h = 0 # Handle movement if Input.GetKey(KeyCode.A) or Input.GetKey(KeyCode.Left): h -= 1 if Input.GetKey(KeyCode.D) or Input.GetKey(KeyCode.Right): h += 1 transform.Position += Vector2(h * speed * Time.DeltaTime, 0)
JavaScript is also supported in Unilarity for game scripting.
var moveInput = Vector2.Zero; var animator, sr, rb; function Awake() { animator = gameObject.GetComponent(SpriteAnimator); sr = gameObject.GetComponent(SpriteRenderer); rb = gameObject.GetComponent(Rigidbody2D); } function Update() { // Handle movement var h = 0; if (Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.Left)) h -= 1; if (Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.Right)) h += 1; transform.Position = new Vector2( transform.Position.X + h * 120 * Time.deltaTime, transform.Position.Y ); }