I was following a tutorial where the gameobject was to spawn randomly within the screen. The code I used is as follows.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class NewBehaviourScript : MonoBehaviour
{
// Start is called before the first frame update
// jump location support
//screen dimensions
float minX = -3.77f;
float maxX = 3.73f;
float minY = -2.13f;
float maxY = 2.16f;
//timer support
const float TotalJumpDelaySeconds = 1;
float elapsedJumpTimeSeconds = 0;
// Update is called once per frame
void Update()
{
//update timer and check if its done
elapsedJumpTimeSeconds += Time.deltaTime;
if(elapsedJumpTimeSeconds >= TotalJumpDelaySeconds)
{
elapsedJumpTimeSeconds = 0;
Vector3 position = transform.position;
position.x = Random.Range(minX, maxX);
position.y = Random.Range(minY, maxY);
}
}
}
But on running the game it stays in the same location
Here is the code in text

