- Home /
Question by
elias070707 · Nov 20, 2020 at 08:42 PM ·
2d gameunity 2d
how can I ceep position z on 0
When I spawn object position z go -8000 and go at the camera.
Comment
Answer by elias070707 · Nov 20, 2020 at 08:46 PM
spawn code using System.Collections; using System.Collections.Generic; using UnityEngine;
public class DeatHoleScript : MonoBehaviour {
[SerializeField]Transform spawnPoint;
void OnCollisionEnter2D(Collision2D col)
{
if(col.transform.CompareTag("Player"))
{
col.transform.position = spawnPoint.position;
}
}
}
Answer by obsidianz · Nov 20, 2020 at 09:18 PM
if(col.transform.tag == "Player")
{
Vector3 pos = spawnPoint.position;
pos.z = 0;
col.transform.position = pos;
}
Sorry, I´m so starter. How can I specify pos?
Assets\DeatHoleScript.cs(13,13): error CS0103: The name 'pos' does not exist in the current context
You are probably trying to use the Vector3 pos
outside of the if statement. If you define a variable inside an if statement it will no longer exist after you leave the if area.