Update Only Once

Hello GameDev . I want to develop the Garden Glitch for android and I am stucked in one problem.
I want to update the Trophy only once Trophy is instantiating very fast not stoppig.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class TrophySpawner : MonoBehaviour
{
Player player;
float min = 0.000001f;
[SerializeField] GameObject Trophy;
void Update()
{
SpawnTrophy(GetTrophyClicked());
}

public void PlayerSelected(Player selectedPlayer)
{
    player = selectedPlayer;
}

private Vector2 GetTrophyClicked()
{
    Vector3 WorldTop = Camera.main.ViewportToWorldPoint(new Vector3((float)0.1, (float)0.12, Camera.main.nearClipPlane));
    Vector3 WorldBase = Camera.main.ViewportToWorldPoint(new Vector3((float)0.4, min, Camera.main.nearClipPlane));
    Vector2 worldPos = new Vector2(Random.Range(WorldBase.x, WorldTop.x), Random.Range(WorldTop.y, WorldBase.y));
    Vector2 gridPos = SnapToGrid(worldPos);
    return gridPos;
}

private Vector2 SnapToGrid(Vector2 rawWorldPos)
{
    float newX = Mathf.RoundToInt(rawWorldPos.x);
    float newY = Mathf.RoundToInt(rawWorldPos.y);
    return new Vector2(newX, newY);
}

public void SpawnTrophy(Vector2 roundedPos)
{
   
  //  Vector2 initantiatePos = new Vector2(Random.Range(WorldBase.x, WorldTop.x), Random.Range(WorldTop.y, WorldBase.y));
    Player newPlayer =  Instantiate(player, roundedPos, Quaternion.identity) as Player;
}

}

Here is the code . I want instantiate only once. So please help me.

Hi Subit,

Unfortunately, developing games for mobile platforms is outside the scope of this course. Please feel free to ask our helpful community of students for advice in our official Discord chat.

This topic was automatically closed after 3 hours. New replies are no longer allowed.

Privacy & Terms