I’m trying to keep the joystick in the bottom left corner but Screen.width0.0f and Screen.height0.0f points to the top left corner while Touch.position shows x==0,y==0 in the bottom left corner… why? I switched the landscape mode around in case that was it but it didn’t work.
It’s very important both matches, so I can compare positions and know where exactly it was touched.
Here’s my script:
(Hopefully not too messy)
using UnityEngine;
using System.Collections;
public class J1 : MonoBehaviour {
public Texture2D[] JoystickImages=null;
float MEM1,MEM2;
Vector2 MEM3,MEM4;
int JOYstandard=999;
Vector2[] Sectionsa=new Vector2[5],Sectionsb=new Vector2[5];
const float IncrementsMEM3=0.20f;
float yValuea=0.99f,xValuea=0.00f,yValueb=0.80f,xValueb=0.20f;
// int HALFSIZE=75;//HALF OF 150 DRAWTEXTURE WIDTH HEIGHT
// Use this for initialization
void Start () {
MEM1=JoystickRect.width;
MEM2=JoystickRect.height;
MEM3=new Vector2(JoystickRect.x+(MEM1*0.5f),JoystickRect.y+(MEM2*0.5f));
for (int i=0;i<5;++i){
Sectionsa_=new Vector2(MEM3.x+xValuea,MEM3.y*yValuea);_
Sectionsb_=new Vector2(MEM3.x+xValueb,MEM3.yyValueb);_
_ yValuea=yValuea-IncrementsMEM3;_
_ yValueb=yValueb-IncrementsMEM3;_
_ }*_
_ /_
_ //COLUMN 1 ROWS _
_ Col1Section1a=new Vector2(MEM3.x0.00f,MEM3.y0.99f);
Col1Section1b=new Vector2(MEM3.x0.20f,MEM3.y0.80f);
Col1Section2a=new Vector2(MEM3.x0.00f,MEM3.y0.79f);
Col1Section2b=new Vector2(MEM3.x0.20f,MEM3.y0.60f);
Col1Section3a=new Vector2(MEM3.x0.00f,MEM3.y0.59f);
Col1Section3b=new Vector2(MEM3.x0.20f,MEM3.y0.40f);
Col1Section4a=new Vector2(MEM3.x0.00f,MEM3.y0.39f);
Col1Section4b=new Vector2(MEM3.x0.20f,MEM3.y0.20f);
Col1Section5a=new Vector2(MEM3.x0.00f,MEM3.y0.19f);
Col1Section5b=new Vector2(MEM3.x0.20f,MEM3.y*0.00f);
/
} /_
* Original (Touch)*
_ x0.0f Left_
_ x1.0f Right_
_ y0.0f Bottom_
_ y1.0f Top_
_ Next (Screen.width0.0f,Screen.height0.0f)_
_ x0.0f Left_
_ x1.0f Right_
_ y1.0f Bottom_
_ y0.0f Top_
_ */ _
* void OnGUI(){*
* GUI.DrawTexture(JoystickRect,JoystickImages[1],ScaleMode.StretchToFill,true,Screen.width/Screen.height);*
* }*
_ Rect JoystickRect=new Rect(Screen.width0.00f,Screen.height0.00f,150,150);
//Rect JoystickRect=new Rect(Screen.width0.05f,Screen.height0.7f,150,150);_
* void Update () {*
* foreach (Touch touch in Input.touches){*
* if (touch.phase== TouchPhase.Moved||touch.phase==TouchPhase.Began){*
* float Deconstructor1=touch.position.x;*
* float Deconstructor2=touch.position.y;*
* for (int i=0;i<5;++i){*
if (Deconstructor1>Sectionsa.x&&Deconstructor1<Sectionsb.x&&Deconstructor2>Sectionsa_.y&&Deconstructor2<Sectionsb*.y){
JOYstandard=i;}else{}
}}}}}*_