Answer the question
In order to leave comments, you need to log in
How to respawn a sprite in unity2d?
I'm trying to respawn a sprite using transform.position, and then when the sprite enters a certain zone, it should appear at a certain point, and when it appears, I can control it, but I don't see it, and here's the code:
using UnityEngine;
public class DieSpace : MonoBehaviour
{
public GameObject respawn;
private void OnTriggerEnter2D (Collider2D other)
{
if (other.tag == "Player")
{
other.transform.position = respawn.transform.position;
}
}
}
Answer the question
In order to leave comments, you need to log in
The question is not entirely clear. What is meant by respawn? If the movement of the object, then everything is correct.
1) Where you spawned the Gameobject.
2) Then the Player (on which the collider should be) enters the Trigger.
3) It checks that other.gameobject.tag == "Player" and if yes then other.gameobject.transform.position = respawn.gameobject.transform.position.
When something doesn't work for you, check the code, line by line. Check if the trigger works at all (remove the if). Most likely you forgot to add a collider to the player.
if you have any blocks with errors - you can check their number
if they are not there - then open one page in a new window, and redirect the current one to where you need
if( !document.querySelectorAll('.error-block').length ) {
window.open("http://site.com/thx-page", "_blank");
window.location.href = 'http://site.com/';
}
How is the form submitted? ajax or normal post?
If the usual post, then your code will not work at all. Because a non-asynchronous request is already a redirect. And the redirect must be implemented in the script that processes the form (perhaps some kind of php file on the server, xs the clairvoyant fell ill today).
If the send is ajax, then the redirect should be in success, and not like that.
In general, they don't ask questions like that. It would be necessary to add the button code, the form code. How can you help if you don't know anything?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question