#Unexpected preprocessor directive

1 messages · Page 1 of 1 (latest)

copper plinth
#

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;
    
   
}

}
`

final spoke
#

does that not look weird to you?

copper plinth
#

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

final spoke
#

show the new code

copper plinth
#

`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;
    
   
}

}
`

final spoke
#

you still have this

#

random 'e'

copper plinth
#

Thank you so much

#

im sorry

#

lol

#

but thank you

steady ice
copper plinth
#

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

steady ice
#

these are simple formatting mistakes

#

IDE will offer way to format it properly

copper plinth
#

the intellicode format thinger

#

dev kit

steady ice
#

thats part of it, what about the Unity one and is it configured? if its not underlining where issue is its not configured

copper plinth
#

where would I configure i t

steady ice
#

follow this guide exactly

#

!vscode

rocky mirageBOT
#
Visual Studio Code guide

If your IDE is not underlining errors in red or autocompleting code,
please configure it using the link below:

https://on.unity.com/vscode

steady ice
#

if you're on VSCode assuming

copper plinth
#

thanks

#

yeah i am

#

pretty sure i had already followed all the steps

#

there are colours and it is saying stuff like references

steady ice
#

screenshot the editor for script WindowOpen

copper plinth
#

why WindowOpen

#

Im using InputHandler

steady ice
copper plinth
#

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);

steady ice
copper plinth
#

I am I realized I coulds see the red afterall

#

but I was looking at the wrong script

steady ice
#

okeay

copper plinth
#

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

steady ice
#

so wat is supposed to do cause this only runs on each click
onOrOff = !onOrOff;

it doesnt actually toggle the object

copper plinth
#

oh

#

but if(onOrOff == true) { Square.SetActive(true); } else { Square.SetActive(false); }

steady ice
#

which is on object creation

copper plinth
#

so I just need move that down?

steady ice
#

put it in a method and call the method

#

you only need Square.SetActive(onOrOff) after the onOrOff = !onOrOff;

copper plinth
#

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

steady ice