Синтаксис:
Используется csharp
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Advertisements;
public class Player : MonoBehaviour
{
[SerializeField] private string gameID;
[SerializeField] private bool testMode;
private bool facingRight;
private float speed;
[SerializeField] private float normalSpeed;
[SerializeField] private float jumpForce;
private bool isGrounded;
private Rigidbody2D rb;
private Animator anim;
private void Start()
{
facingRight = true;
speed = 0;
rb = GetComponent<Rigidbody2D>();
anim = GetComponent<Animator>();
if (Advertisement.isSupported)
{
Advertisement.Initialize(gameID, testMode);
}
StartCoroutine(ShowBanner());
}
IEnumerator ShowBanner()
{
while (!Advertisement.IsReady("Banner_Android"))
{
yield return new WaitForSeconds(1);
}
Advertisement.Banner.SetPosition(BannerPosition.TOP_CENTER);
Advertisement.Banner.Show("Banner_Android");
}
private void Update()
{
Move();
if (facingRight == true && speed < 0)
{
Flip();
} else if (facingRight == false && speed > 0)
{
Flip();
}
if (!isGrounded)
{
anim.SetBool("isJumping", true);
}
else
{
anim.SetBool("isJumping", false);
}
}
public void OnLeftButton()
{
if (speed >= 0)
{
speed = -normalSpeed;
}
}
public void OnRightButton()
{
if (speed <= 0)
{
speed = normalSpeed;
}
}
public void ButtonUp()
{
speed = 0;
}
private void Move()
{
rb.velocity = new Vector2(speed, rb.velocity.y);
if (speed > 0)
{
anim.SetBool("isRunning", true);
}
else if (speed < 0)
{
anim.SetBool("isRunning", true);
}
else
{
anim.SetBool("isRunning", false);
}
}
public void Jump()
{
if (isGrounded)
{
rb.AddForce(new Vector2(0, jumpForce));
anim.SetTrigger("takeOff");
}
}
private void Flip()
{
facingRight = !facingRight;
Vector2 Scaler = transform.localScale;
Scaler.x *= -1;
transform.localScale = Scaler;
}
private void OnCollisionEnter2D()
{
isGrounded = true;
}
private void OnCollisionExit2D()
{
isGrounded = false;
}
}
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Advertisements;
public class Player : MonoBehaviour
{
[SerializeField] private string gameID;
[SerializeField] private bool testMode;
private bool facingRight;
private float speed;
[SerializeField] private float normalSpeed;
[SerializeField] private float jumpForce;
private bool isGrounded;
private Rigidbody2D rb;
private Animator anim;
private void Start()
{
facingRight = true;
speed = 0;
rb = GetComponent<Rigidbody2D>();
anim = GetComponent<Animator>();
if (Advertisement.isSupported)
{
Advertisement.Initialize(gameID, testMode);
}
StartCoroutine(ShowBanner());
}
IEnumerator ShowBanner()
{
while (!Advertisement.IsReady("Banner_Android"))
{
yield return new WaitForSeconds(1);
}
Advertisement.Banner.SetPosition(BannerPosition.TOP_CENTER);
Advertisement.Banner.Show("Banner_Android");
}
private void Update()
{
Move();
if (facingRight == true && speed < 0)
{
Flip();
} else if (facingRight == false && speed > 0)
{
Flip();
}
if (!isGrounded)
{
anim.SetBool("isJumping", true);
}
else
{
anim.SetBool("isJumping", false);
}
}
public void OnLeftButton()
{
if (speed >= 0)
{
speed = -normalSpeed;
}
}
public void OnRightButton()
{
if (speed <= 0)
{
speed = normalSpeed;
}
}
public void ButtonUp()
{
speed = 0;
}
private void Move()
{
rb.velocity = new Vector2(speed, rb.velocity.y);
if (speed > 0)
{
anim.SetBool("isRunning", true);
}
else if (speed < 0)
{
anim.SetBool("isRunning", true);
}
else
{
anim.SetBool("isRunning", false);
}
}
public void Jump()
{
if (isGrounded)
{
rb.AddForce(new Vector2(0, jumpForce));
anim.SetTrigger("takeOff");
}
}
private void Flip()
{
facingRight = !facingRight;
Vector2 Scaler = transform.localScale;
Scaler.x *= -1;
transform.localScale = Scaler;
}
private void OnCollisionEnter2D()
{
isGrounded = true;
}
private void OnCollisionExit2D()
{
isGrounded = false;
}
}