how can I specify an area based on a proportion of the screen height/width and have a jump/move image there?

how can I specify an area based on a proportion of the screen height/width for a mobile device and have a jump/move image there?

Easy way is use the UI. Add a canvas to your game then add a button to the canvas. Scale the button to be the size you want then put the anchors at the corner of the button. That will make the button scale with differing screen sizes so it should stay the right size relative to screen size. Like this…

71142-anchorsspng.png

Then we modify that script we talked about in the last question…

using System.Collections;

public class ButtonMovement : MonoBehaviour {

	public Rigidbody2D playerRigidbody;
	private float jumpHeight = 2f;
	private bool isGrounded;
	private float jumpHeldFor = 0f;
	private bool jumpHeld = false;

	// Update is called once per frame
	void Update()
	{
		if (jumpHeld)
			jumpHeldFor = jumpHeldFor + Time.deltaTime;
	}

	public void JumpPressed () {
		jumpHeld = true;
		}

	public void JumpReleased() {
		Debug.Log (jumpHeldFor);
		if (jumpHeldFor > 0f && isGrounded) {
			if (jumpHeldFor < 1.0f) {
				playerRigidbody.AddForce (Vector2.up * jumpHeight, ForceMode2D.Impulse);
			} else if (jumpHeldFor >= 1.0f) {
				playerRigidbody.AddForce (Vector2.up * jumpHeight * 6, ForceMode2D.Impulse);
			}
			jumpHeldFor = 0f;
			jumpHeld = false;
		}
	}

	void OnCollisionEnter2D(Collision2D col)
	{
		if (col.gameObject.name == "ground")
			isGrounded = true;
	}

	void OnCollisionExit2D(Collision2D col)
	{
		if (col.gameObject.name == "ground")
			isGrounded = false;
	}
}

Now go to the button in the inspector and add an Event Trigger component. Add two event types (Pointer Down and Pointer Up). In both drag the player (that should have that script attached to it) onto the empty slot.

Then select the function and choose ButtonMovement → JumpPressed for Pointer Down and ButtonMovement → JumpReleased for Pointer Up.

71143-eventspng.png

And that’s it, the UI will handle mouse or touch in the same way. You don’t need an image for the button so it just looks transparent on the end device.

no it didn’t work this is my hold script

using UnityEngine;
using System.Collections;

public class BottonMovement : TouchManeger {
public enum type {LeftButton, RightButton, JumpButton,PouseButton};
public type buttonType;

public float jumpHeight = 0.0f, moveSpeed  = 0.0f;
public float  lastClick = 0f;
public int isOn = 0;

public  Rigidbody2D playerRigidbody;

public GameObject playerObject;
public GUITexture buttonTexture = null;
public bool isItMoving = false;// if player moves
private float myTouchDT = 0;
private Touch touch;
private bool isGrounded;

private float jumpHeldFor = 0f;
private bool jumpHeld = false;

void Start () {
}
void Update () {
	if (jumpHeld) {
		jumpHeldFor = jumpHeldFor + Time.deltaTime;
	}
}

public void JumpPressed () {
	jumpHeld = true;
	Debug.Log ("jumpPress is true");

}
void OnCollisionEnter2D(Collision2D col)
{
	if (col.gameObject.name == "ground")
		isGrounded = true;
	Debug.Log ("player == ground");

}

void OnCollisionExit2D(Collision2D col)
{
	if (col.gameObject.name == "ground")
		isGrounded = false;
	Debug.Log ("player not ground");

}

public void JumpReleased()
{

	Debug.Log ("jumpReased is true");
	Debug.Log (jumpHeldFor);
	if (jumpHeldFor > 0f && isGrounded){
		Debug.Log ("jumpReased is grounded");
		if (jumpHeldFor < 1.0f)
		{
			Debug.Log ("small jump");
			playerRigidbody.AddForce (Vector2.up * jumpHeight, ForceMode2D.Impulse);
		} else if (jumpHeldFor >= 1.0f)
		{ // aqui ira isItMoving pa que lo active
			if (isItMoving)// if it moving you can use the big jum otherwice u can not
			{
				playerRigidbody.AddForce (Vector2.up * jumpHeight * 1.5f, ForceMode2D.Impulse);
				Debug.Log ("big jump");
			}
		}
		jumpHeldFor = 0f;
		jumpHeld = false;
	}

}

void FixedUpdate () {
	TouchInput (buttonTexture);
}

void OnFirstTouch()
{
	switch (buttonType) {
	case type.LeftButton:
		isItMoving = true;// this is to activate holdjump
		playerObject.transform.eulerAngles = new Vector2 (0, 180);
		playerObject.transform.Translate (Vector2.right * moveSpeed * Time.deltaTime);//move left
		isOn = 1;
		break;
	case type.RightButton:
		isItMoving = true;

		playerObject.transform.eulerAngles = new Vector2 (0,0);
		playerObject.transform.Translate (Vector2.right * moveSpeed * Time.deltaTime);//move right
		isOn = 1;
		break;
	}
}
void OnSecondTouch()
{
	switch (buttonType) {
	case type.LeftButton:
		isItMoving = true;

		playerObject.transform.eulerAngles = new Vector2 (0, 180);// mueve el mono 180 dgrees pa que camine left
		//playerObject.transform.Translate (-Vector2.right * moveSpeed * Time.deltaTime);//move left
		playerObject.transform.Translate (Vector2.right * moveSpeed * Time.deltaTime);//move left
		isOn = 1;
		break;
	case type.RightButton:
		isItMoving = true;

		playerObject.transform.eulerAngles = new Vector2 (0, 0);
		playerObject.transform.Translate (Vector2.right * moveSpeed * Time.deltaTime);//move right
		isOn = 1;
		break;
	}

}

void OnFirstTouchEnded()
{
	isOn = 0;
}
void OnSecondTouchEnded()
{
	isOn = 0;
}

}