Question by
Voky · Nov 17, 2015 at 06:37 PM ·
c#gameobjectinstantiateraycast
No gameobject instance again in update
Hello, I need handle instantiating of GameObject by ,,MarkInst" and ,,CanMarkInst" bool, but when I hit mouse button 0 these bools go false but it still can instantiate when I am hitting mouse button 0... :/ Please help :)
using UnityEngine;
using System.Collections;
public class Smazat : MonoBehaviour {
public Camera cam;
public GameObject Marker;
public bool MarkInst = true;
public bool CanMarkInst = true;
public float x;
public float y;
public float z;
void Update() {
if (Input.GetMouseButton(0))
{
RaycastHit info;
if (Physics.Raycast(cam.ScreenPointToRay(Input.mousePosition), out info))
{
x = info.point.x;
z = info.point.z;
y = info.point.y;
}
if(MarkInst == true && CanMarkInst == true)
{
Instantiate(Marker, new Vector3(x,y,z), Quaternion.Euler(1,1,1));
MarkInst = false;
CanMarkInst = false;
}
}
if (Input.GetMouseButtonUp (0)) {
x = 0;
z = 0;
y = 0;
}
}
}
Comment
Your title and content goes completely against each other. And i didn't understand what you asking for.
Answer by Voky · Nov 18, 2015 at 01:57 PM
I want make unit choosing marker in strategy game and I need on click make only one ,,Marker", but everytime when I hold mouse button 0 it making infinite of ,,Markers"... It doesnt show any errors...