Hello i am new to unity, i have a project for my diploma to make a 2d game.
Can anyone help me to make a script for saving position of a player every 5 seconds ?
Many thanks,
Andrei
Hello i am new to unity, i have a project for my diploma to make a 2d game.
Can anyone help me to make a script for saving position of a player every 5 seconds ?
Many thanks,
Andrei
Some simple ways you could do this would be to use the Time.deltaTime to count the number of seconds that have gone by.
What have you tried so far?
I’ve created this code, now the Enemy follows the Player up and down, between the obstacles. But the Enemy is moving intermittently. Do you know how can i fix that?
And i have one more problem. If the Player goes up and down quickly, the enemy, don’t follow the exact position of the player. I can’t upload the picture to show you.
.public class Enemy : MonoBehaviour
{
public float Speed = 0;
private Transform _playerTransform;
private Transform _myTransform;
void Start()
{
var player = GameObject.FindGameObjectWithTag("Player");
if (!player)
{
Debug.LogError(
"Could not find the main player. Ensure it has the player tag set.");
}
else
{
_playerTransform = player.transform;
}
_myTransform = this.transform;
}
void Update()
{
var moveAmount = Speed * Time.deltaTime;
_myTransform.position = Vector3.MoveTowards(_myTransform.position,
_playerTransform.position, moveAmount);
}
}