- Home /
Some questions that needs answers.
Hi
I have three question that I need help with.
1: Is there any time commando like in C++? Let's say I have a function, so when a function is executed I want some things to happen. And after the time that was inputed in that commando, the things under this commando (in the script) will be executed.
2: How can I make a script that creates a save file, and in the save file there will be saved intiatures, floats, boolean? Or is there a way to save in a better way?
3: Whay is the best way to create a 2D crosshair that the weapon follows? Because I can make it so the weapon/gun targets the crosshair. Or is there a better way to do it.
Answer by CHPedersen · Jan 04, 2012 at 09:18 AM
1:
Scheduling events to occur after a specific amount of time has passed is done using Coroutines, and the "WaitForSeconds(float)" yield instruction in particular. Study this page:
http://unity3d.com/support/documentation/ScriptReference/index.Coroutines_26_Yield.html
2:
Saving single variables is efficiently and easily done using PlayerPrefs, study them here:
http://unity3d.com/support/documentation/ScriptReference/PlayerPrefs.html
If you need more complicated data written to a file, you should resort to the various IO classes in .Net. It's possible you can format it as a string and put it all in a file with a single line of code using File.WriteAllText, but this depends largely on your specific use scenario.
3:
That question has been asked a gazillion times. Try to google for "Unity3d Crosshair", and you'll find plenty of hits. There is even a youtube tutorial for that particular purpose here:
Your answer
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Trying to delay movement of a GameObject 1 Answer
deltatime glitches 1 Answer
How do i place a crosshair to my ray cast? 1 Answer
Problem with time !! help me 1 Answer