#Unexpected preprocessor directive
1 messages · Page 1 of 1 (latest)
This is the error im error im getting and I dont understand the code I have to a full but i still cant figure out why its there
`using UnityEngine;
using UnityEngine.InputSystem;
public class InputHandler : MonoBehaviour
{e
#rgion Variables
public bool onOrOff;
private Camera _mainCamera;
#endregion
private void Awake()
{
_mainCamera = Camera.main;
if(onOrOff == true)
{
Square.SetActive(true);
}
else
{
Square.SetActive(false);
}
}
public void OnClick(InputAction.CallbackContext context)
{
if (!context.started) return;
var rayHit = Physics2D.GetRayIntersection(_mainCamera.ScreenPointToRay(Mouse.current.position.ReadValue()));
if (!rayHit.collider) return;
Debug.Log(rayHit.collider.gameObject.name);
onOrOff = !onOrOff;
}
}
`
does that not look weird to you?
oh my god how did i not notice that
well
Assets\InputHandler.cs(8,5): error CS1585: Member modifier 'public' must precede the member type and name
now I have that
Assets\InputHandler.cs(8,5): error CS1585: Member modifier 'public' must precede the member type and name
show the new code
`using UnityEngine;
using UnityEngine.InputSystem;
public class InputHandler : MonoBehaviour
{e
#region Variables
public bool onOrOff;
private Camera _mainCamera;
#endregion
private void Awake()
{
_mainCamera = Camera.main;
if(onOrOff == true)
{
Square.SetActive(true);
}
else
{
Square.SetActive(false);
}
}
public void OnClick(InputAction.CallbackContext context)
{
if (!context.started) return;
var rayHit = Physics2D.GetRayIntersection(_mainCamera.ScreenPointToRay(Mouse.current.position.ReadValue()));
if (!rayHit.collider) return;
Debug.Log(rayHit.collider.gameObject.name);
onOrOff = !onOrOff;
}
}
`
also, are errors being underlined red in your IDE
crap now im getting this: Assets\WindowOpen.cs(51,1): error CS1022: Type or namespace definition, or end-of-file expected
this is painful and i feel stupid
first make sure your IDE is configured
these are simple formatting mistakes
IDE will offer way to format it properly
thats part of it, what about the Unity one and is it configured? if its not underlining where issue is its not configured
where would I configure i t
if you're on VSCode assuming
thanks
yeah i am
pretty sure i had already followed all the steps
there are colours and it is saying stuff like references
if its not underlinging ur current error then its not configured poperly
screenshot the editor for script WindowOpen
because thats where the error is coming from?
oh crap
so it turns out it was working, i cant see, and that error is gone
however the code im using just does not work now
`using UnityEngine;
using UnityEngine.InputSystem;
public class InputHandler : MonoBehaviour
{
#region Variables
public bool onOrOff;
public GameObject Square;
private Camera _mainCamera;
#endregion
private void Awake()
{
_mainCamera = Camera.main;
if(onOrOff == true)
{
Square.SetActive(true);
}
else
{
Square.SetActive(false);
}
}
public void OnClick(InputAction.CallbackContext context)
{
if (!context.started) return;
var rayHit = Physics2D.GetRayIntersection(_mainCamera.ScreenPointToRay(Mouse.current.position.ReadValue()));
if (!rayHit.collider) return;
Debug.Log(rayHit.collider.gameObject.name);
onOrOff = !onOrOff;
}
}
`
is my current code
its supposed to make it so when I hit an object named App, it toggles Square on and off
there are no errors with it but when I click nothing happens except for the Debug.Log(rayHit.collider.gameObject.name);
you still need to make sure ur coding with proper IDE configured
I am I realized I coulds see the red afterall
but I was looking at the wrong script
okeay
so now the code I sent just doesnt work
no errors but it doesnt do anything
the square is gone at the start
then never comes back
oop i see an error
so wat is supposed to do cause this only runs on each click
onOrOff = !onOrOff;
it doesnt actually toggle the object
oh
but if(onOrOff == true) { Square.SetActive(true); } else { Square.SetActive(false); }
that only happens once in awake
which is on object creation
so I just need move that down?
put it in a method and call the method
you only need Square.SetActive(onOrOff) after the onOrOff = !onOrOff;
okay hold on
{
if (!context.started) return;
var rayHit = Physics2D.GetRayIntersection(_mainCamera.ScreenPointToRay(Mouse.current.position.ReadValue()));
if (!rayHit.collider) return;
Debug.Log(rayHit.collider.gameObject.name);
onOrOff = !onOrOff;
Square.SetActive(onOrOff);
}```
like that?
or no semi
IT WORKS
THANK YOU
