Having troubles with the checkpoints opening on my 2D platformer and its making my sprite dissapear.
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][2] [2]: /storage/temp/111111-checkpoint-inspector.png alt text
Answer by Cuttlas-U · Feb 11, 2018 at 03:27 PM
hi; i read your code and saw your screen shots i think i cant find any problem in these;
so the problem must be else where ? if u have "any desk" programm installed i can take a look at your system ;
Thank you for the reply i have got TeamViewer but i could get any desk if needed
I dont know how much this problem is important for u i usually give this advice if i think the problem is else where ;
sadly $$anonymous$$m viewer is blocked in my country so if u like install Any Desk and send me your id in my gmail : savajjad@gmail.com
good luck
Your answer
![](https://koobas.hobune.stream/wayback/20220612152419im_/https://answers.unity.com/themes/thub/images/avi.jpg)