Scripting - need help to make my script shorter
Hi, I'm not very good in scripting, i've never made c# before using Unity. So i try to do my best but sometimes, it's not very compact and light.
So i'm here to ask your help about this code, that i would like to make shorter / more compact.
using UnityEngine; using System.Collections;
public class Coins : MonoBehaviour
{
public float cash;
voidUpdate(){
if(TileManager.score==1)
{
if(TileManager.score==3)
{
if(TileManager.score==7)
{
if(TileManager.score==10)
{
something like cash = cash + 100
}
ETC ... ... ... ...
else
{
something like cash = cash + 150
}
}
else
{
something like cash = cash + 50
}
}
else
{
something like cash = cash + 30
}
}
else
{
something like cash = cash + 10
}
Maybe my code is wrong, i have not test it yet because i don't want to have this huge code if another way, more compact, to make it exist.
Thank you in advance for your help, have a nice day :)
Answer by Erwin23p · Sep 27, 2016 at 04:12 AM
Hello, I'm learning too, but I'll try to maybe help you. I created the other script too simulating your other script. Well, In the other script I have this:
and in the script you're trying to do, I have this:
I tried, and worked pretty damn well.
I hope I helped you. :D
Hi, thank you for your answer The problem is that the Tile$$anonymous$$anager script that you have done isn't very similar to what i have. $$anonymous$$y script Tile$$anonymous$$anager, add 1 to SCORE when a tile spawn because the player reach the limit of the screen. So in this script, i have just one float which is incremented by 1 when the score grow up.
But thank you for the script you've done, because it realy helped me in my project :)
Hi, I'm glad that It helped you. I need a lot of practice to learn C# and Unity program$$anonymous$$g/scripting so I'm always glad to try to help.
And sorry, I forgot to add some serious explanations: The Tile$$anonymous$$anager is to simulate a way of getting points... so, the important stuff are the boolean, the floats and the GetScore method. all in the update method is to test if it's working. But do you understand what I've done? Or at least, now?
If you want, you can show me your Tile manager script to see if I can help.
So, I'm gonna try to help you a bit more. The cash should grow with every tile spawned, so the cash should go 10 for 1 of score right? I did some modifications, what about now? You just have to call the GetScore method on every tile spawned, and It will add 1 of score and 10 of cash.
I tried, and worked fine.
Your answer
Follow this Question
Related Questions
Unity {[(2D)]} RotateAround while jumping 0 Answers
vehicle transmission script problem 0 Answers
Make enemy patrol without Nav Points? 0 Answers
Rigidbody2D movement is lagging 0 Answers
CAMERAS ERROR , I NEED HELP 0 Answers