первый скрипт:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Ninja : MonoBehaviour
{
[SerializeField] private float speed = 3f;
[SerializeField] private int lives = 5;
[SerializeField] private float jumpForce;
public Rigidbody2D rb;
private bool jump=true;
private SpriteRenderer sprite;
private Animator anim;
public static Ninja Instance { get; set; }
private void FixedUpdate()
{
CeckGround();
}
private statit staite
{
get { return (statit)anim.GetInteger("state"); }
set {anim.SetInteger("staite",(int)value); }
}
private void Awake()
{
rb = GetComponent<Rigidbody2D>();
anim = GetComponent<Animator>();
sprite = GetComponentInChildren<SpriteRenderer>();
}
private void Run()
{
if (jump) staite = statit.run;
Vector3 dir = transform.right * Input.GetAxis("Horizontal");
transform.position = Vector3.MoveTowards(transform.position, transform.position + dir, speed * Time.deltaTime);
sprite.flipX = dir.x < 0.0f;
}
void Update()
{
if (jump) staite = statit.NewAnimation;
if (Input.GetButton("Horizontal"))
Run();
if (Input.GetButtonDown("Jump") && jump)
jumpUp();
}
private void jumpUp()
{
rb.AddForce(transform.up * jumpForce, ForceMode2D.Impulse);
}
private void CeckGround()
{
Collider2D[] collider = Physics2D.OverlapCircleAll(transform.position, 0.5f);
jump = collider.Length > 1;
if (!jump) staite = statit.jumpninja;
}
public void GetDamage()
{
lives -= 1;
Debug.Log(lives);
}
}
public enum statit
{
NewAnimation,
run,
jumpninja
}
и второй:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class monsters : MonoBehaviour
{
private void OnCollisionEnter2D(Collision2D collision)
{
if (collision.gameObject == Ninja.Instance.gameObject)
{
Ninja.Instance.GetDamage();
}
}
}
ошибка:
NullReferenceException: Object reference not set to an instance of an object
monsters.OnCollisionEnter2D (UnityEngine.Collision2D collision) (at Assets/scrips/monsters.cs:10)
помогите решить пожалуйста
P.S. я новичок!