Question by
VroGD · Oct 24, 2016 at 03:43 PM ·
if statement
no idea what is wrong
it stands still with the if structure _onClicked. if i remove that it follows my mouse thats what i want but only if i hold my mousebutton if i release it it should go back.
using UnityEngine; using System.Collections;
public class gameman : MonoBehaviour {
public GameObject ball;
private GameObject currentball;
public GameObject rekker;
private bool loaded = true;
private bool _onClicked = false;
private Vector3 _Startpos;
private Vector3 screenPoint;
//private Vector3 newPosition;
void Start()
{
_Startpos = rekker.transform.position;
}
// Update is called once per frame
void Update()
{
if (loaded)
{
currentball = Instantiate(ball);
currentball.transform.parent = rekker.transform;
currentball.transform.localPosition = Vector3.zero;
loaded = false;
}
if (_onClicked)
{
screenPoint = Camera.main.WorldToScreenPoint(gameObject.transform.position);
Vector3 curScreenPoint = new Vector3(Input.mousePosition.x, Input.mousePosition.y, Input.mousePosition.z + 5);
Vector3 curPosition = Camera.main.ScreenToWorldPoint(curScreenPoint);
rekker.transform.position = curPosition;
}
}
void OnMouseDown()
{
_onClicked = true;
Debug.Log("tru");
}
void OnMouseUp()
{
_onClicked = false;
rekker.transform.position = _Startpos;
Debug.Log("false");
}
}
Comment
Your answer
