I don’t know how you wrote your code but I tried to reformat the code. and it has no errors. Please check the following code :-
using UnityEngine;
using System.Collections;
public class Respawn : MonoBehaviour
{
[SerializeField]
private Vector3
spawn;
// Use this for initialization
void Start ()
{
transform.position = spawn;
}
// Update is called once per frame
void Update ()
{
}
void OnCollisionEnter (Collision other)
{
if (other.transform.tag == "Enemy") {
transform.position = spawn;
}
}
}
Can you please check this now and then tell whether this is helpful or not
please use the “Code Sample” button to input your code in the future, (its the one with 1’s and 0’s on the icon)
this is how your code looks (i guess) :
void OnCollisionEnter(Collision other)
{ //start of void OnCollisionEnter
if (other.transform.tag == "Enemy")
//nothing to do with the "if" statement here, its blank.
} //end of void OnCollisionEnter
//this code is "floating", it does not belong to anything
{
transform.ImagePosition = spawn:
}
a curly bracket will open and close a function (such as void OnCollisionEnter) so when you use one, the compiler assumes you have said all you are going to say about that function and moves on to the next line, which is “floating” and totally unrelated.
just take it easy on the curly brackets man, those things are expensive!
take a look at @itsharshdeep 's code above as to how to correctly format your code.