- Home /
This post has been wikified, any user with enough reputation can edit it.
Question by
MinkiGamerJohn · Oct 11, 2014 at 09:43 PM ·
c#2dcollision
[c#]collision script not working
I have a script that takes collision against walls and if i get to the goal but it does not work I want it to let me drag and drop in the inspector to choose where my player gets teleported
using UnityEngine;
using System.Collections;
public class Collision : MonoBehaviour {
void OnCollisionEnter2D(Collision2D coll,Transform NextSpawn) {
if
(coll.gameObject.tag == "Lava")
Application.LoadLevel (Application.loadedLevel);
else if
(coll.gameObject.tag == "Victory")
Transform.position = (NextSpawn);
}
}
Comment
Please do some tutorials, you are using Transform ins$$anonymous$$d of transform, trying to set a Vector3 variable to a Transform variable and general readability of your code is not great. Check these out!
Best Answer
Answer by 767_2 · Oct 11, 2014 at 09:52 PM
(coll.gameObject.tag == "Victory")
transform.position = NextSpawn.position;
NextSpawn is of type Transform, you need to do NextSpawn.position as well
Your answer
Follow this Question
Related Questions
Object following a path and colliding with other objects with physics. 1 Answer
Simple on Collision Help (C#) 2 Answers
2D Collision problem 1 Answer