- Home /
Question by
Lindron · Dec 07, 2012 at 01:32 AM ·
c#collisions2d platformerlever
2D platformer levers and moving platforms question.
Okay, so I thought I submitted a question, but must have done it wrong and I apologize. I am trying to make a 2D platformer where a player can jump into levers and move corresponding walls. Below is my code which causes unity to lock up. It is the while loop. It apparently never changes wall.transform.position. Can somebody please explain why this is so and how I can fix this?
If any more details are needed, please request them and I will respond asap.
using UnityEngine; using System.Collections;
public class lever : MonoBehaviour
{
public GameObject leverControl;
public GameObject wall;
public GameObject startLocation;
public GameObject endLocation;
private Vector3 start;
private Vector3 end;
private bool wallUp;
// Use this for initialization
void Start ()
{
start = startLocation.transform.position;
end = endLocation.transform.position;
wallUp = true;
}
// Update is called once per frame
void Update ()
{
}
void OnCollisionEnter(Collision Player)
{
if(Player.gameObject.tag == "Player")
{
if(wallUp)
{
while(wall.transform.position != endLocation.transform.position)
{
end = wall.transform.position;
end.y -= .05f;
wall.transform.position.Set (end.x,end.y,end.z);
}
this.transform.Rotate(0,90,0);
wallUp = false;
}
else
{
while(wall.transform.position != startLocation.transform.position)
{
start = wall.transform.position;
start.y += .05f;
wall.transform.position.Set(end.x, end.y, end.z);
}
this.transform.Rotate(0,-90,0);
wallUp = true;
}
}
}
}
Comment
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Losing references made in editor script 1 Answer
C# GetComponent Issue 2 Answers
Grabing and moving a box(C#) 3 Answers