Hi, I have a player who die when he hit something and persist while reloading the level :
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class killer : MonoBehaviour {
public Rigidbody2D collider2;
public player script;
public SpriteRenderer spriteRenderer;
public Sprite sprite;
public GameObject GO;
public bool IsDead;// if already dead
// Use this for initialization
void Start () {
}
void Awake()
{
GameObject[] objs = GameObject.FindGameObjectsWithTag("Player");
DontDestroyOnLoad(this.gameObject);
}
private void OnTriggerEnter2D(Collider2D collision)
{
script.enabled = false;
spriteRenderer.sprite = sprite;
collider2.constraints = RigidbodyConstraints2D.None;
IsDead = true;
Application.LoadLevelAsync(Application.loadedLevelName);
}
}
And a camera who follow him on the x axis
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class cameraplane : MonoBehaviour {
public Transform transformcam;
public Transform transformplane;
public float smooth;
public float offset;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
// the following mechanic
transformcam.position = new Vector3(Mathf.Lerp(transformcam.position.x, transformplane.position.x + offset, Time.deltaTime * smooth), 4.5f ,-10);
}
}
I want the camera to follow ONLY the one who isn't killed.
Please HEEEEEEEEEEEEEEEEEEEEEEEEEEEEEELP
↧