Title says it all…
if(Input.GetMouseButtonDown(2)){
gameObject.active = false
Thats what my noob coding brought me
Title says it all…
if(Input.GetMouseButtonDown(2)){
gameObject.active = false
Thats what my noob coding brought me
if (Input.GetMouseButtonDown (2)) {
Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast (ray, out hit)) {
hit.transform.gameObject.active = false;
}
}
Was that a snip or what cause i got some errors ![]()
I rushed it, but I don’t see any reasons for errors.
What are your errors?
Its in C#.
Parsing Error
I suppose it is a snippet, I didn’t include the class definition.
I’m a little off my rocker today, somehow when you said snippet, I thought pseudo code.
So…
I’m trying to make a front iron sight disappear when zoomed in because I have an ACOG on it.
And IRL you can’t see the front iron sight through an ACOG ![]()
I’m trying to make a front iron sight disappear when zoomed in because I have an ACOG on it.
And IRL you can’t see the front iron sight through an ACOG ![]()
using UnityEngine;
using System.Collections;
public class NewBehaviourScript : MonoBehaviour {
void Update () {
if (Input.GetMouseButtonDown (1)) {
Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast (ray, out hit)) {
hit.transform.gameObject.active = false;
}
}
}
}
Also changed it to use MouseButton 1 (right click)
I attached it to the front iron sight but it didn’t do anything. Should i be attaching it to something else?
Also im sorry for my ignorance
If you are using the TA51 mount on a flat top, it’ll show a little bit along the bottom; however, it will be very out of focus. If you have it mounted on the handle, you shouldn’t see it.
Never noticed lol.
Now that you told what you’re trying to do, you don’t need a raycast at all.
public GameObject ironSight;
void Update () {
if (Input.GetMouseButtonDown (1)) {
ironSight.active = false;
// or ironSight.active = !ironSight.active to toggle
}
}
Hmm 4,19
A namescape can only contain types and namespace declarations
Sorry I could probably fix this but i dont know C# ![]()
Again, did you include the class definition?
using UnityEngine;
using System.Collections;
public GameObject ironSight;
void Update () {
if (Input.GetMouseButtonDown (1)) {
ironSight.active = false;
// or ironSight.active = !ironSight.active to toggle
}
}
So what do i need to add to rid this error?
You missed the ‘public class XXXXX : MonoBehaviour’
using UnityEngine;
using System.Collections;
public class NewBehaviourScript : MonoBehaviour {
public GameObject ironSight;
void Update () {
if (Input.GetMouseButtonDown (1)) {
ironSight.active = false;
// or ironSight.active = !ironSight.active to toggle
}
}
}
oh Well thanks a bunch sir!