Синтаксис:
Используется csharp
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GOLLY : MonoBehaviour {
Rigidbody2D rb;
Animator anim;
void Start() {
rb = GetComponent<Rigidbody2D> ();
anim = GetComponent<Animator> ();
}
void Update() {
if(Input.GetKeyDown(KeyCode.W)) {
jump();
}
if (Input.GetAxis("Horizontal") == 0)
{
anim.SetInteger("irj", 1);
} else
{
Flip();
anim.SetInteger("irj", 2);
}
}
void Flip()
{
if (Input.GetAxis("Horizontal") > 0)
transform.localRotation = Quaternion.Euler(0, 0, 0);
if (Input.GetAxis("Horizontal") < 0)
transform.localRotation = Quaternion.Euler(0, 180, 0);
}
void FixedUpdate() {
rb.velocity = new Vector2(Input.GetAxis("Horizontal") * 12f, rb.velocity.y);
}
void jump()
{
rb.AddForce(transform.up * 8f, ForceMode2D.Impulse);
}
}
using System.Collections.Generic;
using UnityEngine;
public class GOLLY : MonoBehaviour {
Rigidbody2D rb;
Animator anim;
void Start() {
rb = GetComponent<Rigidbody2D> ();
anim = GetComponent<Animator> ();
}
void Update() {
if(Input.GetKeyDown(KeyCode.W)) {
jump();
}
if (Input.GetAxis("Horizontal") == 0)
{
anim.SetInteger("irj", 1);
} else
{
Flip();
anim.SetInteger("irj", 2);
}
}
void Flip()
{
if (Input.GetAxis("Horizontal") > 0)
transform.localRotation = Quaternion.Euler(0, 0, 0);
if (Input.GetAxis("Horizontal") < 0)
transform.localRotation = Quaternion.Euler(0, 180, 0);
}
void FixedUpdate() {
rb.velocity = new Vector2(Input.GetAxis("Horizontal") * 12f, rb.velocity.y);
}
void jump()
{
rb.AddForce(transform.up * 8f, ForceMode2D.Impulse);
}
}