using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class RandomParkour : MonoBehaviour
{
int x = 0;
int z = 0;
float CoinX = 0.0f;
float CoinZ = 0.0f;
int CoinSpawn = 0;
int PrevX = 0;
int PrevZ = 0;
System.Random random = new System.Random();
public GameObject Platform;
public GameObject Player;
public GameObject Coin;
void Update()
{
if ( Player.transform.position.y > transform.position.y - 5 )
{
do
{
x = random.Next(-4, 4);
}
while ( (x == PrevX) || (x == PrevX - 1) || (x == PrevX + 1));
do
{
z = random.Next(-4, 4);
}
while ( (z == PrevZ) || (z == PrevZ - 1) || (z == PrevZ + 1));
CoinSpawn = random.Next(1, 10);
if (CoinSpawn == 1)
{
System.Random random = new System.Random();
CoinX = transform.position.x;
CoinZ = transform.position.z;
Coin.transform.position = new Vector3(CoinX, transform.position.y + 1, CoinZ);
GameObject duplicate = Instantiate(Coin);
}
transform.position = new Vector3( x , transform.position.y + 2 , z );
Platform.transform.position = transform.position;
GameObject duplicate = Instantiate(Platform);
PrevX = x;
PrevZ = z;
}
}
}
so the code on line 55 works, the code on line 49 doesnāt! anyone know why?
And yes, I know the code is messy but oh well.
And the error code if it helps in any way.
Assets\Scripts\RandomParkour.cs(50,28): error CS0136: A local or parameter named āduplicateā cannot be declared in this scope because that name is used in an enclosing local scope to define a local or parameter