I have set up a checkpoint and the sprite of the flag starts of closed but when the character walks through the checkpoint and touches the circle collider the character disappears and when I click on the scene the character is nowhere to be found. Here are some screenshots of what is happening and my code. This is the script for the player:using UnityEngine;
using System.Collections;
public class PlayerController : MonoBehaviour
{
public float moveSpeed;
private Rigidbody2D myRigidbody;
public float JumpSpeed;
public Transform groundCheck;
public float groundCheckRadius;
public LayerMask whatIsGround;
public bool isGrounded;
private Animator myAnim;
// Use this for initialization
void Start()
{
myRigidbody = GetComponent<Rigidbody2D>();
myAnim = GetComponent<Animator>();
}
// Update is called once per frame
void Update()
{
isGrounded = Physics2D.OverlapCircle(groundCheck.position, groundCheckRadius, whatIsGround);
if (Input.GetAxisRaw("Horizontal") > 0f)
{
myRigidbody.velocity = new Vector3(moveSpeed, myRigidbody.velocity.y, 0f);
transform.localScale = new Vector3(0.4f, 0.4f, 0.3f);
}
else if (Input.GetAxisRaw("Horizontal") < 0f)
{
myRigidbody.velocity = new Vector3(-moveSpeed, myRigidbody.velocity.y, 0f);
transform.localScale = new Vector3(-0.4f, 0.4f, -0.3f);
}
else
{
myRigidbody.velocity = new Vector3(0, myRigidbody.velocity.y, 0f);
}
if (Input.GetButtonDown("Jump") && isGrounded)
{
myRigidbody.velocity = new Vector3(myRigidbody.velocity.x, JumpSpeed, 0f);
}
myAnim.SetFloat("Speed", Mathf.Abs( myRigidbody.velocity.x));
myAnim.SetBool("Grounded", isGrounded);
}
void OnTriggerEnter2D(Collider2D other)
{
if (other.tag == "KillPlane");
{
gameObject.SetActive(false);
}
}
}
here is the script for the checkpoint: using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CheckpointController : MonoBehaviour {
public Sprite flagClosed;
public Sprite flagOpen;
private SpriteRenderer theSpriteRenderer;
public bool CheckpointActive;
// Use this for initialization
void Start () {
theSpriteRenderer = GetComponent<SpriteRenderer>();
}
// Update is called once per frame
void Update () {
}
private void OnTriggerEnter2D(Collider2D other)
{
if (other.tag == "Player")
{
theSpriteRenderer.sprite = flagOpen;
CheckpointActive = true;
}
}
}
alt text