I was following this tutorial and i’ve checked it over several times, and the script seems fine. need help!!!
Tutorial:
Time on video : 22:51
please help!
I was following this tutorial and i’ve checked it over several times, and the script seems fine. need help!!!
Tutorial:
Time on video : 22:51
please help!
Okay, so you have an error on a line… if you open the script and look at that line (or double click the error, it should bring you there, hopefully in the code editor).
Then, for follow up, you can either decipher the problem yourself and/or paste the affect line into the forum here
Cost - Mathf.Round(Cost * 1.15f);
Okay, so are you like trying to adjust the value of cost on that line?
I know you literally posted the line, which I suggested… but for future reference, please feel free to add a few words of your own to help explain lol
If you want to adjust ‘Cost’, try this instead:
Cost -= Mathf.Round(Cost * 1.15f);
You could also do this (same thing):
Cost = Cost - Mathf.Round(Cost * 1.15f);
See the difference to the original code and even what the error was trying to tell you ?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class NewBehaviourScript : MonoBehaviour {
public Click click;
public UnityEngine.UI.Text ItemInfo;
public int Cost;
public int count = 0;
public int clickPower;
public string itemName;
private float _newCost;
void Update()
{
ItemInfo.text = itemName + "\nCost: " + Cost + “\nPower: +” + clickPower;
}
public void PuchasedUpgrade ()
{
if (click.gold >= Cost)
{
click.gold -= Cost;
count += 1;
click.goldperclick += clickPower;
Cost -= Mathf.Round(Cost * 1.15f);
_newCost = Mathf.Pow(Cost, _newCost = Cost) ;
}
}
}
both still have errors
Okay… few things here about your post & code.
Please use code tags when you post code in the forums. There’s a pinned thread about how to do that.
You can even edit your last post so it will be nicer.
Anyhow, luckily it’s not too long and I can read it this time …
You didn’t add that changes I suggested… that’s 1 issue At least not in what you posted.
Next, you can’t use “_newCost = Cost” inside Mathf.Pow
sorry
lol…
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class NewBehaviourScript : MonoBehaviour {
public Click click;
public UnityEngine.UI.Text ItemInfo;
public int Cost;
public int count = 0;
public int clickPower;
public string itemName;
private float _newCost;
void Update()
{
ItemInfo.text = itemName + "\nCost: " + Cost + "\nPower: +" + clickPower;
}
public void PuchasedUpgrade ()
{
if (click.gold >= Cost)
{
click.gold -= Cost;
count += 1;
click.goldperclick += clickPower;
Cost = Cost - Mathf.Round(Cost * 1.15f);
_newCost = Mathf.Pow(Cost, _newCost = Cost) ;
}
}
}
3092770–233338–UpgradeManager.cs (792 Bytes)
Okay, well the error is not the same now… Right? It’s something different
Add a cast: Cost = Cost - (int)Mathf.Round(Cost * 1.15f);
Lets see…starting up unity now x)
it seems to work! thank you!
Cool, you’re welcome
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class UpgradeManager : MonoBehaviour {
public Click click;
public UnityEngine.UI.Text ItemInfo;
public int Cost;
public int count = 0;
public int clickPower;
public string itemName;
private float BaseCost;
void Start()
{
BaseCost = Cost;
}
void Update()
{
ItemInfo.text = itemName + "\nCost: " + Cost + "\nPower: +" + clickPower;
}
public void PuchasedUpgrade()
{
if (click.gold >= Cost)
{
click.gold -= Cost;
count += 1;
click.goldperclick += clickPower;
Cost = Mathf.Round(BaseCost * Mathf.Pow(1.15f, count)) ;
}
}
}
I’m having trouble with: Cost = Mathf.Round(BaseCost * Mathf.Pow(1.15f, count)) ;
in the second tutorial, the guy changes the code yet again, and its not got an error on this line
That’s the exact same error that I last showed you a fix for.
If you want to follow the tutorial exactly (and avoid the problem showing up again), change the type of cost to a float. On your last screenshot, it’s line 10, which should read:
public float Cost;
Or cost (without a capital c, which the tutorial uses), whatever you want, provided it’s consistent throughout your code.