- Home /
character gets out of the window
Hey guys i m new to unity and been using it for sometime so i'l be precise,i've a character,(its just a cube for now actually),and i ve used the following code to move it around the window,
using UnityEngine; using System.Collections;
public class sphere : MonoBehaviour { float playertime =1f; // Use this for initialization void Start () { transform.position = new Vector3 (4, 0, 0); }
// Update is called once per frame
void Update () {
transform.Translate (Vector3.right * Input.GetAxis ("Horizontal")*playertime *Time.deltaTime);
transform.Translate (Vector3.up * Input.GetAxis ("Vertical")*playertime *Time.deltaTime);
}
but the problem is
1)that the cube can get out of the window as the user keeps on pressing the keys so how can you confide the cube/character within the window,no matter how much the keys are pressed the cube never gets out of the window?
2)the next question is that-ii know about the (application.loadlevel)and can load a new level whenever a collsion happens but lets say the collision doesnt happen and the enemies are approaching from the right and the cube/character doesnt collide with the enemies and escapes by jumping and reaches to the end right of the current scene and now as soon as the cube(lets say its similar to mario )is moved forward a new scene has to load and also when the cube returns back the previous scene has to load in the same manner(eg if 2 enemes were destroyed then they should be destroyed not just load the previous scene from beginning.)
so what would the code be like? help would be really appreciable guys,please :)
Your answer
Follow this Question
Related Questions
move to next scene 1 Answer
Move standalone window to upper left corner 0 Answers
Problem with objects colliding and IsSleeping (C#) 1 Answer
CC Collisions, Locking Y Axis 1 Answer
move till collision 1 Answer