dieZel
Green Team
- 08.04.2018
- 230
- 598
Всем здравия господа, делаю 2д платформер на юнити, и понятия не имею, как делать прыжок, код ниже. Гуглил, не особо помогло, код на C#
Код простой,
А я тупой!)
C#:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Move : MonoBehaviour {
public GameObject player;
public int speed = 5;
public bool stay = false;
void Start()
{
player = (GameObject)this.gameObject;
}
void Update()
{
if (Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.LeftArrow))
{
player.transform.position -= player.transform.right * speed * Time.deltaTime;
}
if (Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.RightArrow))
{
player.transform.position += player.transform.right * speed * Time.deltaTime;
}
if (stay == true)
{
if (Input.GetKey(KeyCode.Space) || Input.GetKey(KeyCode.UpArrow) || Input.GetKey(KeyCode.W))
{
GetComponent<Rigidbody2D>().AddForce(new Vector3(0, speed*20, 0), ForceMode2D.Impulse);
}
}
}
void OnCollisionStay2D(Collision2D collision)
{
if (collision.gameObject.tag == "Ground")
{
stay = true;
}
else
{
stay = false;
}
}
}
А я тупой!)