Adding a score and displaying it on the screen (and other scripting questions)?

Hello, I am developing a 2D shooter and I have some questions regarding the scripting. I am able to understand the basic logic and process of what needs to be done

1: How would I add a score to the game and then display it using the GUI skin (not just plain text)? How would I then access (call?) the function that increases the score from any script (with a variable amount of points) so I can have many things that increase the score?

2: How would I display a timer on the GUI skin?

3: When the mouse is clicked, I want to make the bullet object move outward from the player in the direction of the mouse cursor (and If the mouse it held down, it would be rapid fire), how would this be done? The game is along the ZX plane if that helps.

4: How would I make a crosshair decal move 1 to 1 with the mouse cursor?

5: How can I spawn objects using the score/timer values (ex: at 1 minute spawn Z about of object A)?

Thank you. I know I have alot of complex questions.

Anyone have an answer to ANY of the questions?

The score can simply be displayed using a GUI.Label in function OnGUI();
You can have a local variable which holds the actual score int, which you can display in the label.

First check out http://unity3d.com/support/resources/unite-presentations/in-game-gui-made-easy to get familiar with the GUI elements.
Then check out some youtube tutorials like this one; http://www.youtube.com/watch?v=JEMdbT7HWqw

A GUI Skin is something you apply on top of the GUI, again, check out the presentation of ‘ingame gui made easy’.

Check out the FPS tutorial at http://unity3d.com/support/resources/example-projects/

I haven’t done anything like this, but I would imagine making a GUI Texture, and changing the position of the element according to the mouse position(see the script reference for the mouse pos)

What do you mean by this ?

Good luck,

Eamon

Thank you. Can you please give me a code example of “a local variable which holds the actual score int”? This would be the actual score, correct?

Something like this ?

 private var score:int = 0;

 function OnGUI()
 {
   GUI.Label(Rect(100,100, 100, 50), score);
 }

I looked into a script from the FPS tutorial you suggested.

var projectile : Rigidbody; 
var speed = 20; 
function Update() 
{ 
 if( Input.GetButtonDown( "Fire1" ) ) 
 { 
  var instantiatedProjectile : Rigidbody = Instantiate( 
   projectile, transform.position, transform.rotation ); 
  instantiatedProjectile.velocity = 
   transform.TransformDirection( Vector3( 0, 0, speed ) ); 
  Physics.IgnoreCollision( instantiatedProjectile. collider, 
   transform.root.collider ); 
 } 
}

In its un-modified version, it would just should shoot another object up (along the Z axis, since its a 2D game).
But when I modified it to this (I swapped for Event.mousePosition) it makes the object it shooting move very quickly to the side (and sometimes straight at the camera). Whats wrong?

var projectile : Rigidbody; 
var speed = 2; 
function Update() 
{ 
 if( Input.GetButtonDown( "Fire1" ) ) 
 
 { 
  var instantiatedProjectile : Rigidbody = Instantiate( 
   projectile, transform.position, transform.rotation ); 
   
  instantiatedProjectile.velocity = 
   transform.TransformDirection
   (Event.mousePosition); 
 } 
 
      }

I have also tried "Input.mousePosition " and I couldn’t get that to work either, any help?

To get a vector from the current player position to the mouse position, you need to use vector subtraction to get a vector pointing in the right direction:-

var fireDirection = Input.mousePosition - transform.position;

To launch a projectile in that direction, you shouldn’t use this vector directly since it will affect the launch speed. Instead, normalise the vector and multiply it by the speed you want to fire with:-

instantiatedProjectile.velocity = fireDirection.normalized * fireSpeed;