I am trying to make it so I can make a button wherever I drag the game object to. This is my latest working code:
using UnityEngine;
using System.Collections;
public class ButtonScript : MonoBehaviour {
public Texture2D icon;
public float posX;
public float posY;
public string LevelToLoad;
public int sizeX;
public int sizeY;
Vector3 thisposition;
// Use this for initialization
void Start () {
posX = this.transform.position.x;
posY = this.transform.position.y;
thisposition = Camera.main.WorldToScreenPoint (new Vector3 (posX, posY, 0));
}
void OnGUI()
{
GUI.backgroundColor = Color.red;
if (GUI.Button (new Rect (thisposition.x, thisposition.y, sizeX, sizeY), icon)) {
Application.LoadLevel (LevelToLoad);
}
}
// Update is called once per frame
void Update () {
}
}
the only problem is the Y axis is inverted and I can’t figure out how to fix the Y co-ord so it’s not inverted. Thanks for any help!