C
C#2y ago
alaa2008

❔ c# unity error

in unity i am getting this error here:
Feature `declaration expression` cannot be used because it is not part of the C# 6.0 language specification
Feature `declaration expression` cannot be used because it is not part of the C# 6.0 language specification
the full code is here: https://pastebin.com/KzChaicv, line 35. can someone please help me?
91 Replies
Buddy
Buddy2y ago
Are you using a Unity version from 2005? /s
alaa2008
alaa2008OP2y ago
i am using the version 2017.3
Buddy
Buddy2y ago
Why? Just install Unity 2021 and you should be good
JakenVeina
JakenVeina2y ago
I mean, theberrorbis pretty clear: you're using a language feature that's not supported in C#6
alaa2008
alaa2008OP2y ago
the project was made with this version
JakenVeina
JakenVeina2y ago
either don't use that, or changenyour C# version
alaa2008
alaa2008OP2y ago
how i am new to c# sorry. so how am i able to fix that ?
JakenVeina
JakenVeina2y ago
what line is the error?
alaa2008
alaa2008OP2y ago
35
alaa2008
alaa2008OP2y ago
JakenVeina
JakenVeina2y ago
yeah
alaa2008
alaa2008OP2y ago
its the out thing
JakenVeina
JakenVeina2y ago
change that line to be valid syntax for C#6, or lookup how to change C# versioning under Unity
alaa2008
alaa2008OP2y ago
ok thx bro this one here ?
alaa2008
alaa2008OP2y ago
ThatDaniel
ThatDaniel2y ago
just replace the var with the type thats your issue. C#7 implemented using var with out you cannot change the C# version without upgrading the editor version
Buddy
Buddy2y ago
You can also convert a project to a newer Unity version
alaa2008
alaa2008OP2y ago
how to replace it with type sorry for asking
ThatDaniel
ThatDaniel2y ago
what is states dictionary(?) of what
alaa2008
alaa2008OP2y ago
ThatDaniel
ThatDaniel2y ago
ok then the type is State<T, K> try putting that instead of the var
alaa2008
alaa2008OP2y ago
ok like this?
alaa2008
alaa2008OP2y ago
ThatDaniel
ThatDaniel2y ago
whats the error saying?
alaa2008
alaa2008OP2y ago
well i gotta translate it because its german
alaa2008
alaa2008OP2y ago
ThatDaniel
ThatDaniel2y ago
oh it might be this:
State<T, K> value2;
if(states.TryGetValue(value, out value2))
State<T, K> value2;
if(states.TryGetValue(value, out value2))
alaa2008
alaa2008OP2y ago
ok let me try YES IT WORKED THANK YOU SO MUCH BRO also i hope its okay if you also help me with this
alaa2008
alaa2008OP2y ago
alaa2008
alaa2008OP2y ago
the error says:
alaa2008
alaa2008OP2y ago
alaa2008
alaa2008OP2y ago
full code:
alaa2008
alaa2008OP2y ago
Pastebin
```using SBS.Math;using UnityEngine;namespace SBS.Core{ public c...
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
alaa2008
alaa2008OP2y ago
line 45
ThatDaniel
ThatDaniel2y ago
you havent got two TimeSource classes in different namespaces? I can only think that the TimeSource in the TimeManager is using a different type and not the SBS.Core.TimeSource
alaa2008
alaa2008OP2y ago
Let me see If i have two thats the only namespace there
alaa2008
alaa2008OP2y ago
alaa2008
alaa2008OP2y ago
any idea how to fix the error? this error here i mean
ThatDaniel
ThatDaniel2y ago
does the error show in the Unity console?
alaa2008
alaa2008OP2y ago
no only in visual studio
ThatDaniel
ThatDaniel2y ago
restart visual studio
alaa2008
alaa2008OP2y ago
ok nope i am still getting the error but the error doesn't appear in unity
ThatDaniel
ThatDaniel2y ago
If you can enter play mode then I've got no idea why VS is saying its wrong
alaa2008
alaa2008OP2y ago
let me try now i am getting the error in unity
alaa2008
alaa2008OP2y ago
ThatDaniel
ThatDaniel2y ago
Honestly cannot see whats wrong with that try restarting Unity
alaa2008
alaa2008OP2y ago
yea i know why the error appears i have another script called FSM and there is another error with the timeSource this one here
alaa2008
alaa2008OP2y ago
alaa2008
alaa2008OP2y ago
and this one here
alaa2008
alaa2008OP2y ago
alaa2008
alaa2008OP2y ago
this one here is the in the timeSource script and this one here is in the FSM script
alaa2008
alaa2008OP2y ago
so thats the TimeSource script: https://pastebin.com/YjvBDp1j and this one here the FSM script: https://pastebin.com/iwk9jdu4
Pastebin
```using SBS.Math;using UnityEngine;namespace SBS.Core{ public c...
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
Pastebin
using System.Collections.Generic;namespace SBS.Core{ public clas...
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
alaa2008
alaa2008OP2y ago
the timeSource script error is in line 44 and FSM script error in line 61 maybe thats the problem idk or nah nah its not that i was wrong i still don't know why i get that error @ThatDaniel that thing with == does it require something called operator overloads ? uh i got again the error here
alaa2008
alaa2008OP2y ago
alaa2008
alaa2008OP2y ago
the out thing
alaa2008
alaa2008OP2y ago
alaa2008
alaa2008OP2y ago
any idea how to fix that?
Thinker
Thinker2y ago
What does the error say?
alaa2008
alaa2008OP2y ago
like this
Thinker
Thinker2y ago
Declare the variable before the if statement
int value;
if (numObjectsByCat.TryGetValue(category, out value))
int value;
if (numObjectsByCat.TryGetValue(category, out value))
alaa2008
alaa2008OP2y ago
ok let me try
alaa2008
alaa2008OP2y ago
Thinker
Thinker2y ago
out value sorry
alaa2008
alaa2008OP2y ago
no worries now its working thx
Thinker
Thinker2y ago
catok
alaa2008
alaa2008OP2y ago
uh talking about the ref
alaa2008
alaa2008OP2y ago
alaa2008
alaa2008OP2y ago
using UnityEngine;

[ExecuteInEditMode]
[AddComponentMenu("NGUI/UI/Orthographic Camera")]
[RequireComponent(typeof(Camera))]
public class UIOrthoCamera : MonoBehaviour
{
private Camera mCam;

private Transform mTrans;

private void Start()
{
mCam = GetComponent<Camera>();
mTrans = ((Component)this).transform;
mCam.orthographic = true;
}

private void Update()
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
//IL_0021: Unknown result type (might be due to invalid IL or missing references)
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
//IL_0046: Unknown result type (might be due to invalid IL or missing references)
//IL_004b: Unknown result type (might be due to invalid IL or missing references)
Rect rect = mCam.rect;
float num = ((Rect)(ref rect)).yMin * (float)Screen.height;
Rect rect2 = mCam.rect;
float num2 = ((Rect)(ref rect2)).yMax * (float)Screen.height;
float num3 = (num2 - num) * 0.5f * mTrans.lossyScale.y;
if (!Mathf.Approximately(mCam.orthographicSize, num3))
{
mCam.orthographicSize = num3;
}
}
}
using UnityEngine;

[ExecuteInEditMode]
[AddComponentMenu("NGUI/UI/Orthographic Camera")]
[RequireComponent(typeof(Camera))]
public class UIOrthoCamera : MonoBehaviour
{
private Camera mCam;

private Transform mTrans;

private void Start()
{
mCam = GetComponent<Camera>();
mTrans = ((Component)this).transform;
mCam.orthographic = true;
}

private void Update()
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
//IL_0021: Unknown result type (might be due to invalid IL or missing references)
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
//IL_0046: Unknown result type (might be due to invalid IL or missing references)
//IL_004b: Unknown result type (might be due to invalid IL or missing references)
Rect rect = mCam.rect;
float num = ((Rect)(ref rect)).yMin * (float)Screen.height;
Rect rect2 = mCam.rect;
float num2 = ((Rect)(ref rect2)).yMax * (float)Screen.height;
float num3 = (num2 - num) * 0.5f * mTrans.lossyScale.y;
if (!Mathf.Approximately(mCam.orthographicSize, num3))
{
mCam.orthographicSize = num3;
}
}
}
what can i do there to get that error fixed?
alaa2008
alaa2008OP2y ago
Buddy
Buddy2y ago
What are you trying to do?
alaa2008
alaa2008OP2y ago
in the script there are two errors the ref
Buddy
Buddy2y ago
yes, so remove it
alaa2008
alaa2008OP2y ago
thats it?
Buddy
Buddy2y ago
Are you trying to mod a game?
alaa2008
alaa2008OP2y ago
no i decompiled a script from a game
Buddy
Buddy2y ago
Which game is that?
alaa2008
alaa2008OP2y ago
Motorway-Mayhem so now that i removed the ref things in unity i am getting this here
alaa2008
alaa2008OP2y ago
Buddy
Buddy2y ago
You don't need ref for that $refvsvalue
Buddy
Buddy2y ago
Which you should use when passing to methods - if needed
alaa2008
alaa2008OP2y ago
ok 👍 also if you don't mind me asking this in unity how do i know which script goes where nvm nvm got it sup guys i hope you all have a great day i hope you guys don't mind helping me out a little bit
alaa2008
alaa2008OP2y ago
Pastebin
using System.Collections.Generic;using SBS.Core;using SBS.Math;usin...
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
alaa2008
alaa2008OP2y ago
its this error here
alaa2008
alaa2008OP2y ago
alaa2008
alaa2008OP2y ago
alaa2008
alaa2008OP2y ago
line 28 well i got that fixed got another error
alaa2008
alaa2008OP2y ago
alaa2008
alaa2008OP2y ago
alaa2008
alaa2008OP2y ago
line 93
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server