Вот первый код
using UnityEngine;
using System.Collections;
public class Control : MonoBehaviour {
public float speed = 10f;
public bool Grounded = false;
public Transform GroundCheck;
public float GroundRadius = 0.2f;
public LayerMask wtfIsGround;
private bool faceRight = true;
Rigidbody2D rig;
void Start () {
rig = GetComponent();
}
void Update () {
Grounded = Physics2D.OverlapCircle (GroundCheck.position, GroundRadius, wtfIsGround);
if (Input.GetKeyDown (KeyCode.Space) && Grounded) {
rig.AddForce (new Vector2 (0, 800f));
}
float move;
move = Input.GetAxis ("Horizontal");
rig.velocity = new Vector2 (move * speed, rig.velocity.y);
if (move > 0 && !faceRight)
flip ();
else if (move < 0 && faceRight)
flip ();
}
void flip () {
faceRight = !faceRight;
transform.localScale = new Vector3 (transform.localScale.x * -1, transform.localScale.y, transform.localScale.z);
}
private void OnTriggerEnter2D (Collider2D collision) {
if (collision.tag.Equals("Money"))
{
MoneyCollect.MoneyCount += 1;
Destroy(collision.gameObject);
}
}
}
Вот второй
using UnityEngine;
using UnityEngine.UI
public class MoneyCollect : MonoBehaviour {
public static int MoneyCount;
private Text MoneyConter;
void Start ()
{
MoneyConter = GetComponent();
MoneyCount = 0;
}
void Update ()
{
MoneyConter.text = "X" + MoneyCount;
}
}
-
Вопрос задан
-
63 просмотра