OnGui

Pleas Help with my script. I have 3 Problems :

  1. If i touch anywhere else on the screen i cant touch with an other finger the GuiButton
  2. If i hold the GuiButton only 1 Bullet comes out so how can i do it that if i hold the GuiButton that more than 1 Bullet comes out
  3. How can i make it that the GuiButton is always on the right upper corner on all screens with different resolutions.

This is my script so far:

var projectil : Rigidbody;
var timer : float = 1;
var speed : float = 1;

function Update ()
{
timer -= Time.deltaTime;
}

function OnGUI () {
if (GUI.Button (Rect (0,50,100,50), “Shoot”)) {
if ( timer <= 0 )
{
timer -= timer += speed;
Instantiate(projectil ,transform.position ,transform.rotation);
}
}
}

Thanks

  1. I’m assuming you’re trying to use touch input. If so, are you building for Android? As far as I’m aware, Unity Android doesn’t distinguish between multiple finger touches, but Unity iPhone does.

  2. Try using GUI.RepeatButton. That is called every frame the button is clicked; GUI.Button only works in the frame it is clicked, i.e. only once per click.

  3. Check the Gui Basics here. In particular, have a look at the Screen.height and Screen.width properties.

I hope this is somewhat useful.

Thanks for the quick answer.
So cant i move and shoot at the same time (I am using android)

Unity definitely can use multiple touches on Android. However, OnGUI was never designed for multi-touch, and as of last time I used it I think it takes the average position of all fingers as a single mouse input. Unless something has changed since then, if you want multi-touch then you’ll either need to use something else for your GUI, or write your own buttons with multi-touch support.