Of course I can blame the tools… just see above
Lol
Seriously, though this is the simplest project I have worked on ever in any language. Heck I coded most of it at work out of boredom… in notepad, with no unity in sight…
- Antagonist.js deals only with moving the moving the enemy player around, pausing the enemy and instantiating the bullets.
2.Constants.js has nothing but enums and global variables
- MainMenu.js is in a completely different scene altogether
- projectile.js deals only with it’s own transform and sends a Die message upon impact.
- Protagonist.js deals with moving the player character
- Scoring.js deals with the display of scores

Allow me:
Scoring.js
var theFont : Font;
var scorePosition : Rect;
static var Info : String;
static var currentScore : int;
private var theStyle : GUIStyle;
static function AdjustScore(by : float)
{
currentScore += by;
}
function Start()
{
currentScore = 0;
theStyle = new GUIStyle();
theStyle.font = theFont;
theStyle.normal.textColor = Color(1,0,0,1);
}
function OnGUI()
{
GUI.Label(scorePosition, currentScore + Info, theStyle);
}
Protagonist:
var maxLeft : float = -5.0;
var maxRight : float = 5.0;
var moveSpeed : float = 5;
var Avatar : Transform;
var Positions : Vector3[];
private var Avatars : Transform[];
private var Lives : int;
private var theEnemy : GameObject;
private var enemyCode : antagonist;
function Start()
{
Lives = Positions.length;
Avatars = new Transform[Lives];
for (x = 0; x < Avatars.length; x++)
{
var obj : Transform = Instantiate(Avatar, Positions[x], Quaternion.identity);
obj.parent = transform;
Avatars[x] = obj;
}
theEnemy = GameObject.Find("Enemy");
enemyCode = theEnemy.GetComponent(antagonist);
}
function Update()
{
if (Lives == 0)
return;
if (Input.GetButtonDown("Horizontal"))
{
var distance : float = moveSpeed * Time.deltaTime;
if (Input.GetAxis ("Horizontal") < 0)
{
transform.position.x -= distance;
} else
if (Input.GetAxis ("Horizontal") > 0)
{
transform.position.x += distance;
}
if (transform.position.x < maxLeft)
transform.position.x = maxLeft;
if (transform.position.x > maxRight)
transform.position.x = maxRight;
}
for (x=0; x< Avatars.length; x++)
{
var Av : Transform = Avatars[x];
var obj : Animation = Av.FindObjectOfType(Animation);
// if (touchPositionDelta.x < 0)
// obj.animation.Play("MoveLeft",PlayMode.StopAll);
// else obj.animation.Play("MoveRight", PlayMode.StopAll);
}
}
function Die()
{
if (enemyCode.GetMoveState() == eMoveState.GameOver)
return;
if (Lives > 0)
{
Lives--;
Destroy(Avatars[Lives].gameObject);
} else
{
enemyCode.ChangeState(eMoveState.GameOver);
}
}
And finally dragcontroller.js:
var theProtagonist : protagonist;
var playerHitRange : float = 4.0;
var isDragging : boolean;
function Start()
{
theProtagonist = GetComponent(protagonist);
}
function OnMouseDown()
{
isDragging = true;
}
function OnMouseUp()
{
if ( isDragging )
{
isDragging = false;
}
}
function ContainedWithin( a: Vector3, b: Vector3, epsilon : float ) : boolean
{
return ( a.x >= b.x - epsilon a.x <= b.x + epsilon
a.y >= b.y - epsilon a.y <= b.y + epsilon );
}
// Update is called once per frame
function Update ()
{
if( Input.GetMouseButtonDown(0))
{
var mousePos : Vector3 = Input.mousePosition;
mousePos.z = -Camera.main.transform.position.z;
mousePos = Camera.main.ScreenToWorldPoint( mousePos );
if ( ContainedWithin( mousePos, transform.position, playerHitRange ) )
{
OnMouseDown();
}
}
else if(Input.GetMouseButtonUp(0))
{
OnMouseUp();
}
}
function FixedUpdate()
{
var pos : Vector3 = Input.mousePosition;
pos.z = Mathf.Abs( Camera.main.transform.position.z );
var ray = Camera.main.ScreenPointToRay (pos);
var hit : RaycastHit;
if (Physics.Raycast (ray, hit, 100))
{
Debug.DrawLine (ray.origin, hit.point);
var p : Vector3 = theProtagonist.Positions[0];
var v : Vector3 = Vector3(hit.point.x, 0.5, -4.26);
transform.position = v;
}
Scoring.Info = " " + hit.point + " --> " + transform.position;
}
The only thing moving my character is the mouse move and the Input.GetAxis(“Horizontal”). Don’t tell me theAccelerator works with the Input.GetAxis command ???
I can’t see what else could me moving my player all over the place. Have a look at dragcontroller… there is no time for anything else to move the prefab between my assigning the value and moving it to the GUI for display…
This is why I am so confused and asking for help. I cannot seem to find the problem with the above code… Please oh please tell me you see something clear and plain and obvious that I am overlooking!!!