- Home /
c# generator problem with counter
the counter don't get minus this is the generator script
float randomCoins;
[SerializeField] Transform GePoint;
[SerializeField] GameObject diamondPrefab;
public bool pause = false;
public static generatCoin ins;
public int counter=0;
private void Awake()
{
ins = this;
}
public Transform countener;
void Start()
{
countener = GameObject.Find("countener").transform;
randomCoins = PlayerPrefs.GetInt(Tags.instance.chanceforGold);
}
float[] arx = { -2.0f, 0.0f, 2.0f };
private int arrayselect;
public void restposition()
{
transform.position = new Vector3(0, 0, 20);
foreach (Transform d in countener)
{
Destroy(d.gameObject);
}
counter = 0; pause = false;
}
void Update()
{
if (pause == true) return;
if (transform.position.z <= GePoint.position.z && counter < 60)
{
arrayselect = Random.Range(0, 3);
var d = Random.Range(0, 111);
if (d < 50)
Instantiate(diamondPrefab, new Vector3(transform.position.x * 0 + arx[arrayselect], transform.position.y + 1.355f, transform.position.z), Quaternion.identity, countener);
transform.position = new Vector3(transform.position.x, transform.position.y, transform.position.z + 5f);
counter++;
}
}
and i try to access the counter value from coin script but it's didn't work i don't know why this is the coin script
GameObject @object;
private void Awake()
{
@object = GameObject.Find(Tags.instance.PlatforDeactivePoint);
}
// Use this for initialization
void Start()
{
RaycastHit hit;
if (Physics.Raycast(transform.position, Vector3.down, out hit, 5))
{
if (hit.collider.gameObject.GetComponent<KillDireckt>() == null) return;
else {
generatCoin.ins.counter -= 1;
Destroy(this.gameObject);
}
}
}
private void OnTriggerEnter(Collider other)
{
if (other.gameObject.tag == Tags.instance.Player)
{
int temp = PlayerPrefs.GetInt(Tags.instance.gold, 0);
temp += 1;
PlayerPrefs.SetInt(Tags.instance.gold, temp);
PlayerPrefs.Save();
generatCoin.ins.counter -= 1;
Destroy(this.gameObject);
}
}
private void Update()
{
if (transform.position.z < @object.transform.position.z)
{
generatCoin.ins.counter -= 1;
Destroy(gameObject);
}
}
the @object; this is the Game object to see the distance how far it's
Does the coin script even compile?
You can't use the '@' symbol anywhere in identifiers, and they must always start with a letter or an underscore. So, @object
is not an valid identifier name.
https://docs.microsoft.com/en-us/windows/desktop/msi/identifier
You can use @ before variables, it's used if you want to use reserved keyword as a variable name.
https://stackoverflow.com/questions/429529/what-does-the-symbol-before-a-variable-name-mean-in-c
oh yeah thanks i think that was problem too but the problem was from unity i just restart it and work the counter thanks guys
Hey @josh15 I'm glad it's working for you now.
I also want to thank @Casiell and @DawidNorasDev for letting me know about the usage of the '@' symbol. Although it's good to have such knowledge, I prefer to stick to Design Guidelines and Na$$anonymous$$g Conventions, and not use the '@' symbol in such a way:
AVOID using identifiers that conflict with keywords of widely used program$$anonymous$$g languages.
According to Rule 4 of the Common Language Specification (CLS), all compliant languages must provide a mechanism that allows access to named items that use a keyword of that language as an identifier. C#, for example, uses the @ sign as an escape mechanism in this case. However, it is still a good idea to avoid common keywords because it is much more difficult to use a method with the escape sequence than one without it.
Your answer
![](https://koobas.hobune.stream/wayback/20220612181244im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Illuminating a 3D object's edges OnMouseOver (script in c#)? 1 Answer
help change script GrassGenerator !! 0 Answers
Terrain Generator Producing Completely Flat Results. 1 Answer