- Home /
Instantiate the prefebd while count text increcreses its value
Hi all,
I have a score counter in my game I want to Instantiate a new gameobject while score was increased by 1
my code is
public static int score;
`void Update () {
score = move.count;
if(score>=spawnTime)
/
SpawnRandom();
}` ,
public void SpawnRandom()
{
direction = new Vector2 (-4.41f,1.99f);
randomNumber = Random.Range (1, 3);
switch (randomNumber) {
case 1:
white= Instantiate(apple,direction,Quaternion.identity);
//
break;
case 2:
Instantiate(red,direction,Quaternion.identity);
break;
}
}
Answer by MT369MT · Aug 20, 2018 at 05:49 PM
Hi, create a new variable that you use to check if the score has changed, like this:
public static int score;
public int maxScore;
void Update ()
{
if (score > maxScore)
{
SpawnRandom();
maxScore = score;
}
}
Thanks for ur reply ,
if count is 0- show the one prefeb object randomly ,if count is 1 change the prefeb object and chose another one.
But in my game it is showing 10 objects at each case plz help me
Could you please explain better your problem? Are you talking about the score system or the random spawning?
both the systems sir, In my game I have a reference object and some objects are falling down, if we catch the correct one which is shown in reference then score will incresed by 1 at that time we have to change the reference object too.
thankyou.
Thanks for ur reply ,
if count is 0- show the one prefeb object randomly ,if count is 1 change the prefeb object and chose another one.
But in my game it is showing 10 objects at each case plz help me
Your answer
Follow this Question
Related Questions
GUI Help, timer and counter 1 Answer
How to give a bonus every 1000 points? 2 Answers
Dual Timer Problems 1 Answer
Using Time.deltaTime as time counter. 1 Answer
deactivate un-used zeros 2 Answers