2075 / Unity / 2D / Гравець / Простий скрипт
| PlayerSimple2D |
public float speed = 10f; public float jumpForce = 10f; Rigidbody2D rb; void Start() { rb = GetComponent<Rigidbody2D>(); } void Update() { Vector3 dir = transform.right * Input.GetAxis("Horizontal"); transform.position = Vector3.MoveTowards(transform.position, transform.position + dir, speed * Time.deltaTime); if (Input.GetButtonDown("Jump")) { rb.AddForce(transform.up * jumpForce, ForceMode2D.Impulse); } }
