Quantcast
Channel: Questions in topic: "error message"
Viewing all articles
Browse latest Browse all 2891

The object of type 'Transform' has been destroyed but you are still trying to access it

$
0
0
when my player object destroy this error happen, any help? using System.Collections; using System.Collections.Generic; using UnityEngine; public class Player_move : MonoBehaviour { [SerializeField] float player_speed = 1; [SerializeField] float player_jump = 1; public int playerhealth = 3; bool isjump; Rigidbody2D rb; SpriteRenderer sr; Animator ar; void Start() { rb = GetComponent(); sr = GetComponent(); ar = GetComponent(); } void Update() { if (Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.LeftArrow)) { ar.Play("player run"); sr.flipX = true; } else if (Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.RightArrow)) { ar.Play("player run"); sr.flipX = false; } if (Input.GetButtonDown("Jump") && isjump == false) { ar.Play("player jump"); rb.velocity = new Vector2(0, player_jump); isjump = true; } if(Mathf.Abs(rb.velocity.y) < 0.01f) { isjump = false; } } private void FixedUpdate() { rb.velocity = new Vector2(player_speed * Input.GetAxis("Horizontal") , rb.velocity.y); } private void OnTriggerEnter2D(Collider2D collision) { if (collision.CompareTag("Enemy") || collision.CompareTag("Enemy_2") || collision.CompareTag("Enemy_3")) { playerhealth--; Debug.Log(playerhealth); ar.Play("player wawa"); } if(playerhealth == 0) { Destroy(gameObject); } } }

Viewing all articles
Browse latest Browse all 2891

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>