- Home /
Question by
sebastianrosspower · Dec 17, 2018 at 02:41 PM ·
c#error messagemacosxmacbook
Upgrade C# language version to 7.0 Mac in Unity?,Upgrade project to C# language version '7.0' on a Mac?
I have to upgrade my C# language version to 7.0 for a project. This is the code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Char : MonoBehaviour {
public float Speed = 5f;
public float SSpeed = 10f;
public float jump = 10f;
public bool gc = false;
public bool GroundTouch = false;
public Text countText;
public Text winText;
private int count;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (Input.GetKey(KeyCode.W) && Input.GetKey(KeyCode.LeftShift))
{
transform.position += Vector3.forward * Time.deltaTime * SSpeed;
}
if (Input.GetKey(KeyCode.A))
{
transform.position += Vector3.left * Speed * Time.deltaTime;
}
if (Input.GetKey(KeyCode.S))
{
transform.position += Vector3.back * Speed * Time.deltaTime;
}
if (Input.GetKey(KeyCode.D))
{
transform.position += Vector3.right * Speed * Time.deltaTime;
}
if (Input.GetKey(KeyCode.Space))
{
transform.position += Vector3.up * jump * Time.deltaTime;
}
Vector3 gc = transform.TransformDirection(Vector3.down);
if (Physics.Raycast (transform.position, gc, .5f))
{
GroundTouch = true;
}
void OnTriggerEnter(Collider other)
{
if (other.gameObject.CompareTag("Pickup"))
{
other.gameObject.SetActive(false);
count = count + 1;
SetCountText();
}
}
void SetCountText ()
{
countText.text = "Score: " + count.ToString();
if (count >= 7)
{
winText.text = "CONGATULATIONS, YOU WON!";
}
}
}
}
Just reminding you that this is on a Mac computer, and Windows solutions will not work. This is my error message:
Feature 'local functions' is not available in C# 4. Please use language version 7.0 or greater.
Thanks in advance!,I am creating a game with Unity and I get an error saying I have to upgrade C# language version to 7.0. On Windows I see people doing it but on Mac I can't find a way to upgrade the language on a Mac. Please help.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Char : MonoBehaviour {
public float Speed = 5f;
public float SSpeed = 10f;
public float jump = 10f;
public bool gc = false;
public bool GroundTouch = false;
public Text countText;
public Text winText;
private int count;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (Input.GetKey(KeyCode.W) && Input.GetKey(KeyCode.LeftShift))
{
transform.position += Vector3.forward * Time.deltaTime * SSpeed;
}
if (Input.GetKey(KeyCode.A))
{
transform.position += Vector3.left * Speed * Time.deltaTime;
}
if (Input.GetKey(KeyCode.S))
{
transform.position += Vector3.back * Speed * Time.deltaTime;
}
if (Input.GetKey(KeyCode.D))
{
transform.position += Vector3.right * Speed * Time.deltaTime;
}
if (Input.GetKey(KeyCode.Space))
{
transform.position += Vector3.up * jump * Time.deltaTime;
}
Vector3 gc = transform.TransformDirection(Vector3.down);
if (Physics.Raycast (transform.position, gc, .5f))
{
GroundTouch = true;
}
void OnTriggerEnter(Collider other)
{
if (other.gameObject.CompareTag("Pickup"))
{
other.gameObject.SetActive(false);
count = count + 1;
SetCountText();
}
}
void SetCountText ()
{
countText.text = "Score: " + count.ToString();
if (count >= 7)
{
winText.text = "CONGATULATIONS, YOU WON!";
}
}
}
}
My exact error message was
Feature 'local functions' is not available in C# 4. Please use language version 7.0 or greater
.Thank you in advance!
Comment
Best Answer
Answer by Vicarian · Dec 17, 2018 at 02:40 PM
You don't need C# 7 for this code. It's improperly formatted. The functions OnTriggerEnter and SetCountText are nested in the Update function. Move them out and it will work:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Char : MonoBehaviour {
public float Speed = 5f;
public float SSpeed = 10f;
public float jump = 10f;
public bool gc = false;
public bool GroundTouch = false;
public Text countText;
public Text winText;
private int count;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (Input.GetKey(KeyCode.W) && Input.GetKey(KeyCode.LeftShift))
{
transform.position += Vector3.forward * Time.deltaTime * SSpeed;
}
if (Input.GetKey(KeyCode.A))
{
transform.position += Vector3.left * Speed * Time.deltaTime;
}
if (Input.GetKey(KeyCode.S))
{
transform.position += Vector3.back * Speed * Time.deltaTime;
}
if (Input.GetKey(KeyCode.D))
{
transform.position += Vector3.right * Speed * Time.deltaTime;
}
if (Input.GetKey(KeyCode.Space))
{
transform.position += Vector3.up * jump * Time.deltaTime;
}
Vector3 gc = transform.TransformDirection(Vector3.down);
if (Physics.Raycast (transform.position, gc, .5f))
{
GroundTouch = true;
}
} // end of Update function
void OnTriggerEnter(Collider other)
{
if (other.gameObject.CompareTag("Pickup"))
{
other.gameObject.SetActive(false);
count = count + 1;
SetCountText();
}
}
void SetCountText ()
{
countText.text = "Score: " + count.ToString();
if (count >= 7)
{
winText.text = "CONGATULATIONS, YOU WON!";
}
}
}
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Unloading Broken Assembly | How to solve this !? 2 Answers
How can I solve this problem using Mapbox in Unity 2 Answers