Quantcast
Channel: Latest Questions on Unity Answers
Viewing all articles
Browse latest Browse all 171066

I need some clarification with constructors

$
0
0
So, I was reading a little bit about constructors and though I have a little experience coding and stuff I still need someone to explain something to me. First off what is the difference between the next sets of code, the first one is using a constructor and the second one isn't. using UnityEngine; using System.Collections; public class backShot : MonoBehaviour { public class backshot { public float BASETIME; public float FRONTBASETIME; public float COOLDOWN; public float FRONTCOOLDOWN; public float TIMERESET; public float ZEROTIME; public backshot(float baseTime, float frontBaseTime, float coolDown, float frontCoolDown,float timeReset, float zeroTime) { BASETIME = baseTime; FRONTBASETIME = frontBaseTime; COOLDOWN = coolDown; FRONTCOOLDOWN = frontCoolDown; TIMERESET = timeReset; ZEROTIME = zeroTime; } } public backshot backShooting = new backshot(4.0f, 4.0f, 0.4f, 0.1f, 4.0f, 0.0f); Here is the second one using UnityEngine; using System.Collections; public class backShot : MonoBehaviour { public float BASETIME = 10.0f; public float FRONTBASETIME = 10.0f; public float COOLDOWN = 10.0f; public float FRONTCOOLDOWN = 20.0f; public float TIMERESET = 20.0f; public float ZEROTIME 0.0f; void start() { } } Again, I just want to know the difference of having a class with a constructor and one without a constructor. I also would like to know if it is ok to use constructors in Unity, I have heard it is not a good practice. Thanks in advance for your answers.

Viewing all articles
Browse latest Browse all 171066

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>