- Home /
respawn problem
the first code for control the socond one for check point
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class plzbegood : MonoBehaviour
{
public float speed = 5f;
public float jumpSpeed = 0f;
private float movement = 0f;
private Rigidbody2D rigidBody;
public Transform groundCheckPoint;
public float groundCheckRadius;
public LayerMask groundLayer;
private bool isTouchingGround;
private Animator playeranimation;
private bool facingRight;
public Vector3 respawnPoint;
// Start is called before the first frame update
void Start()
{
rigidBody = GetComponent<Rigidbody2D>();
playeranimation = GetComponent<Animator>();
}
// Update is called once per frame
void Update()
{
isTouchingGround = Physics2D.OverlapCircle(groundCheckPoint.position, groundCheckRadius, groundLayer);
movement = Input.GetAxis("Horizontal");
if (movement > 0f)
{
rigidBody.velocity = new Vector2(movement * speed, rigidBody.velocity.y);
transform.localScale = new Vector2(13.34f, 13.34f);
}
else if (movement < 0f)
{
rigidBody.velocity = new Vector2(movement * speed, rigidBody.velocity.y);
transform.localScale = new Vector2(-13.34f, 13.34f);
}
else
{
rigidBody.velocity = new Vector2(0, rigidBody.velocity.y);
}
if (Input.GetButtonDown("Jump") && isTouchingGround)
{
rigidBody.velocity = new Vector2(rigidBody.velocity.x, jumpSpeed);
}
playeranimation.SetFloat("speed", Mathf.Abs(rigidBody.velocity.x));
playeranimation.SetBool("OnGround", isTouchingGround);
}
void Onriggerenter2D(Collider2D other)
{
if(other.gameObject.tag == "FallDetector")
{
transform.position = respawnPoint;
}
if(other.tag == "checkpoint")
{
respawnPoint = other.transform.position;
}
}
}
.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class checkpoint : MonoBehaviour
{
public Sprite purpleheart;
public Sprite redheart;
private SpriteRenderer checkpointSpriteRenderer;
public bool checkpointReached;
// Start is called before the first frame update
void Start()
{
checkpointSpriteRenderer = GetComponent<SpriteRenderer>();
}
// Update is called once per frame
void Update()
{
}
void OnTriggerEnter2D(Collider2D other)
{
if (other.tag == "Player")
{
checkpointSpriteRenderer.sprite = redheart;
checkpointReached = true;
}
}
}
Comment
Answer by chrisf112233 · May 06, 2020 at 04:35 AM
Line 66 on first code for control says "OnriggerEnter2D", missing the T, "OnTriggerEnter2D", is that the problem?
I'll appreciate you (OnTriggerEnter2D), but basel23 didn't describe his issue completely!!
Your answer
Follow this Question
Related Questions
help with death zone/respawn 1 Answer
Character Re-spawn Problem 0 Answers
Mulitple spawn points with random seed. 3 Answers
Enemy HealthBar Problems 2 Answers
unity3d multiplayer respawn 2 Answers