You are on page 1of 1

public class PlataformaMovil : MonoBehaviour { // salir de una colision

void OnCollisionExit2D(Collision2D col)


public Transform target; {
public float speed; if (col.gameObject.tag == "Ground")
{
private Vector3 start, end; player.grounded = false;
}
// Use this for initialization if (col.gameObject.tag == "Platform")
void Start () { {
if (target != null) { player.transform.parent = null;
target.parent = null; player.grounded = false;
start = transform.position; }
end = target.position; }
} }
}
public class PlayerController : MonoBehaviour {
void FixedUpdate() {
if (target != null) { public float speed = 2f;
float fixedSpeed = speed * Time.deltaTime; public float maxSpeed = 5f;
transform.position = public bool grounded;
Vector3.MoveTowards(transform.position, target.position, public float jumpPower = 6.5f;
fixedSpeed);
} private Rigidbody2D rb2d;
private Animator anim;
if (transform.position == target.position) { private bool jump;
target.position = (target.position == start) ?
end : start; // Use this for initialization
} void Start () {
} rb2d = GetComponent<Rigidbody2D>();
} anim = GetComponent<Animator>();
}
public class DrawSceneLine : MonoBehaviour {
// Update is called once per frame
public Transform from; void Update () {
public Transform to; anim.SetFloat("Speed", Mathf.Abs(rb2d.velocity.x));
anim.SetBool("Grounded", grounded);
// Use this for initialization if (Input.GetKeyDown(KeyCode.UpArrow) && grounded)
void OnDrawGizmosSelected() { { jump = true; }
if (from != null && to != null) { }
Gizmos.color = Color.cyan;
Gizmos.DrawLine(from.position, to.position); void FixedUpdate() {
Gizmos.DrawSphere(from.position, 0.15f);
Gizmos.DrawSphere(to.position, 0.15f); Vector3 fixedVelocity = rb2d.velocity;
} fixedVelocity.x *= 0.75f;
}
} if (grounded) { rb2d.velocity = fixedVelocity; }

public class CheckGround : MonoBehaviour { float h = Input.GetAxis("Horizontal");


private PlayerController player;
private Rigidbody2D rb2d; rb2d.AddForce(Vector2.right * speed * h);
float limitedSpeed = Mathf.Clamp(rb2d.velocity.x, -
// Use this for initialization maxSpeed, maxSpeed);
void Start () { rb2d.velocity = new Vector2(limitedSpeed,
player = GetComponentInParent<PlayerController>(); rb2d.velocity.y);
rb2d = GetComponentInParent<Rigidbody2D>();
} if(h>0.1f){
transform.localScale = new Vector3(1f, 1f, 1f);
void OnCollisitionEnter2D(Collision2D col) }
{ if (h < -0.1f)
if (col.gameObject.tag == "Platform") {
{ transform.localScale = new Vector3(-1f, 1f, 1f);
rb2d.velocity = new Vector3(0f,0f,0f); }
player.transform.parent = col.transform; if (jump) {
player.grounded = true; rb2d.velocity = new Vector2(rb2d.velocity.x, 0);
} rb2d.AddForce(Vector2.up * jumpPower,
} ForceMode2D.Impulse);
jump = false;
// comprobar si estamos chocando }
void OnCollisionStay2D (Collision2D col) { }
if (col.gameObject.tag == "Ground") {
player.grounded = true; } //que aparezca de nuevo el mono cuando se cae
if (col.gameObject.tag == "Platform") void OnBecameInvisible() {
{ transform.position = new Vector3(-1, 0, 0);
player.transform.parent = col.transform; }
player.grounded = true; }
}
}

You might also like