0

I used to write my game in visual studio however it just happend to be way to weak to handle it and i decided to switch to unity and also take my code with me. In vs2015 i used C# 6 but i think unity is still on older version because it wont accept some of my lines as proper here are few examples

protected override double percentageIncrease { get; } = StatsIncreaments.MagicPowerIncreament;

this is really weird because it accepts auto properties with only get and set but this one is not recognized as proper.

Also any expression bodied functions are not tolerated as well :

public double CalculateExperience() => currentLevel * (currentLevel * 1.1) * 10;

Is there any way to make unity accept my code ?

PetqImaQkaputka
  • 147
  • 1
  • 1
  • 7
  • Assigning values in `Awake` or `Start` instead of at declaration should work (if using a MonoBehaviour), otherwise use a constructor. – Gunnar B. Jun 30 '16 at 18:34
  • Thanks that seems to fix the first problem, but what about the expression bodied functions should i just change them into normal functions ? – PetqImaQkaputka Jun 30 '16 at 18:39
  • If this is just a simple getter function you could also use a property. – Gunnar B. Jun 30 '16 at 18:43
  • I changed all of my properties with get and set to get value from the constructor now i get this error **percentageIncrease.get' must have a body because it is not marked abstract or extern. The property can be automatically implemented when you define both accessors** – PetqImaQkaputka Jun 30 '16 at 18:48
  • are you aware UNITY USES AN OLD VERSION OF MONO. it is trivial to look at the manual for this. – Fattie Jun 30 '16 at 18:49
  • I'm writing in visual studio 2015 if it matters. – PetqImaQkaputka Jun 30 '16 at 18:50
  • you can instantly google answers here http://docs.unity3d.com/412/Documentation/ScriptReference/MonoCompatibility.html – Fattie Jun 30 '16 at 18:52
  • The error should go away when you add a `set`, because you try to assign a value without having a setter. – Gunnar B. Jun 30 '16 at 18:54
  • hopefully the whole question will go away :) – Fattie Jun 30 '16 at 20:20

0 Answers0