Jump to content

Unity Compile errors

Jackb
Go to solution Solved by Jackb,

The Error is that the code i am using is outdated with GUIText what can i use instead of GUIText. it saying that i should use UI.Text but when i put it in it says UI.Text hasnt been found

 

What can i do?

Hi i am having difficulties with unity 3d C# coding and it is due to not being able to enter play mode due to compile errors in my scripts. on most forums it says just find the errors through console but there is nothing in the console. p.s. i need to fix this or i am wasting 200 dollars i put in for a coding course D:

Link to comment
Share on other sites

Link to post
Share on other sites

Just now, Jackb said:

Hi i am having difficulties with unity 3d C# coding and it is due to not being able to enter play mode due to compile errors in my scripts. on most forums it says just find the errors through console but there is nothing in the console. p.s. i need to fix this or i am wasting 200 dollars i put in for a coding course 😧

Make sure you have set the errors to show:

image.png.d92c32af807318f8c91f6089bb591f75.png

They may be set to invisible now.

Ensure your scripts are saved too and check for red underlines there too; that could indicate your error too.

"We're all in this together, might as well be friends" Tom, Toonami.

 

mini eLiXiVy: my open source 65% mechanical PCB, a build log, PCB anatomy and discussing open source licenses: https://linustechtips.com/topic/1366493-elixivy-a-65-mechanical-keyboard-build-log-pcb-anatomy-and-how-i-open-sourced-this-project/

 

mini_cardboard: a 4% keyboard build log and how keyboards workhttps://linustechtips.com/topic/1328547-mini_cardboard-a-4-keyboard-build-log-and-how-keyboards-work/

Link to comment
Share on other sites

Link to post
Share on other sites

Just now, minibois said:

Make sure you have set the errors to show:

image.png.d92c32af807318f8c91f6089bb591f75.png

They may be set to invisible now.

Ensure your scripts are saved too and check for red underlines there too; that could indicate your error too.

oh it was so simple all along im so dumb thanks

Link to comment
Share on other sites

Link to post
Share on other sites

The Error is that the code i am using is outdated with GUIText what can i use instead of GUIText. it saying that i should use UI.Text but when i put it in it says UI.Text hasnt been found

 

What can i do?

Link to comment
Share on other sites

Link to post
Share on other sites

14 minutes ago, Jackb said:

The Error is that the code i am using is outdated with GUIText what can i use instead of GUIText. it saying that i should use UI.Text but when i put it in it says UI.Text hasnt been found

 

What can i do?

Can we get some code :)

Link to comment
Share on other sites

Link to post
Share on other sites

14 hours ago, Jackb said:

The Error is that the code i am using is outdated with GUIText what can i use instead of GUIText. it saying that i should use UI.Text but when i put it in it says UI.Text hasnt been found

 

What can i do?

Depends on the commands. Some are still in use but deprecated. Depends on the version you use. Idk if they took it out yet. 

 

the on gui commands are completely different to The new UI system. You cannot translate it. 

Link to comment
Share on other sites

Link to post
Share on other sites

  • 2 weeks later...

Hello i fixed the recent problem but i am coding a third person character and this code will not work either it says on line 31 there is a

{

 

}

expected but i already have one here is the code

 

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class GameCamera : MonoBehaviour
{

    [SerializeField] private GameObject target;
    [SerializeField] private GameObject rotationAnchorObject;
    [SerializeField] private Vector3 TranslationOffset;
    [SerializeField] private Vector3 followOffset;
    [SerializeField] private float maxViewingAngle;
    [SerializeField] private float minViewingAngle;

    private float verticalRotationAngle;

    private void FixedUpdate()
    {
        //make the camera look at target
        float yAngle = target.transform.eulerAngles.y;
        Quaternion rotation = Quaternion.Euler(0, yAngle, 0);

        transform.position = target.transform.position - (rotation * followOffset);
        transform.LookAt(target.transform.position + TranslationOffset);

        //make the character look up or down
        verticalRotationAngle += Input.GetAxis("Mouse Y");
        if (verticalRotationAngle > maxViewingAngle) ;
        {
            verticalRotationAngle = maxViewingAngle;
        }
        else if (verticalRotationAngle < minViewingAngle)
        {
            verticalRotationAngle = minViewingAngle;
        }
        transform.RotateAround(rotationAnchorObject.transform.position, rotationAnchorObject.transform.right, - verticalRotationAngle);
    }
}
 

Link to comment
Share on other sites

Link to post
Share on other sites

  • 4 weeks later...

Hello everyone i have one last request i am coding a door currently and my script doesnt seem to work apparently the reference Door does not exist even though i have a door script here is the player script

Link to comment
Share on other sites

Link to post
Share on other sites

7 hours ago, Jackb said:

Hello everyone i have one last request i am coding a door currently and my script doesnt seem to work apparently the reference Door does not exist even though i have a door script here is the player script

Spoiler

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Player : MonoBehaviour
{

    [Header("Focal Point variables")]
    [SerializeField] private GameObject focalPoint;
    [SerializeField] private float focalDistance;
    [SerializeField] private float focalSmoothness;
    [SerializeField] private KeyCode changeFocalSideKey;

    [Header("Interaction")]
    [SerializeField] private GameObject gameCamera;
    [SerializeField] private KeyCode interactionKey;
    [SerializeField] private float interactionDistance;

    private bool isFocalPointOnLeft = true;
    
    // Start is called before the first frame update
    void Start()
    {
        Cursor.lockState = CursorLockMode.Locked;
    }

    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown(changeFocalSideKey))
        {
            isFocalPointOnLeft = !isFocalPointOnLeft;
        }

        float targetX = focalDistance * (isFocalPointOnLeft ? -1 : 1);
        float smoothX = Mathf.Lerp(focalPoint.transform.localPosition.x, targetX, focalSmoothness * Time.deltaTime);
        focalPoint.transform.localPosition = new Vector3(smoothX, focalPoint.transform.localPosition.y, focalPoint.transform.localPosition.z);

        // Interaction logic
#if UNITY_EDITOR
        // Draw the Interaction line
        Debug.DrawLine(gameCamera.transform.position, gameCamera.transform.position + gameCamera.transform.forward * interactionDistance, Color.green);
#endif
        if (Input.GetKeyDown(interactionKey))
        {
            RaycastHit hit;
            if (Physics.Raycast(gameCamera.transform.position, gameCamera.transform.forward, out hit, interactionDistance))
            {
                if (hit.transform.GetComponent<Door>())
                {
                    hit.transform.GetComponent<Door>().Interact();
                }
            }

        }
    }
}

 

Link to comment
Share on other sites

Link to post
Share on other sites

7 hours ago, Jackb said:
  Reveal hidden contents


using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Player : MonoBehaviour
{

    [Header("Focal Point variables")]
    [SerializeField] private GameObject focalPoint;
    [SerializeField] private float focalDistance;
    [SerializeField] private float focalSmoothness;
    [SerializeField] private KeyCode changeFocalSideKey;

    [Header("Interaction")]
    [SerializeField] private GameObject gameCamera;
    [SerializeField] private KeyCode interactionKey;
    [SerializeField] private float interactionDistance;

    private bool isFocalPointOnLeft = true;
    
    // Start is called before the first frame update
    void Start()
    {
        Cursor.lockState = CursorLockMode.Locked;
    }

    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown(changeFocalSideKey))
        {
            isFocalPointOnLeft = !isFocalPointOnLeft;
        }

        float targetX = focalDistance * (isFocalPointOnLeft ? -1 : 1);
        float smoothX = Mathf.Lerp(focalPoint.transform.localPosition.x, targetX, focalSmoothness * Time.deltaTime);
        focalPoint.transform.localPosition = new Vector3(smoothX, focalPoint.transform.localPosition.y, focalPoint.transform.localPosition.z);

        // Interaction logic
#if UNITY_EDITOR
        // Draw the Interaction line
        Debug.DrawLine(gameCamera.transform.position, gameCamera.transform.position + gameCamera.transform.forward * interactionDistance, Color.green);
#endif
        if (Input.GetKeyDown(interactionKey))
        {
            RaycastHit hit;
            if (Physics.Raycast(gameCamera.transform.position, gameCamera.transform.forward, out hit, interactionDistance))
            {
                if (hit.transform.GetComponent<Door>())
                {
                    hit.transform.GetComponent<Door>().Interact();
                }
            }

        }
    }
}

 

I edited your post to use code tags and a spoiler, please ensure to do this in the future when you use long scripts

Community Standards || Tech News Posting Guidelines

---======================================================================---

CPU: R5 3600 || GPU: RTX 3070|| Memory: 32GB @ 3200 || Cooler: Scythe Big Shuriken || PSU: 650W EVGA GM || Case: NR200P

Link to comment
Share on other sites

Link to post
Share on other sites

9 hours ago, OrionFOTL said:

You defined the type "Door" yourself, correct? Where did you define it?

i apologize but i dont understand because i am new to coding but i think you mean the mono behavior in the door script? yes i named it Door

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×