How to reset camera after respawn?
Working on a game based only on the Y axis, I can get the player to respawn but can't get the camera to reset. This is my camera script and the respawn script:
Respawn:
 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class KillPlayer : MonoBehaviour {
     [SerializeField]Transform spawnPoint;
 
 
     void OnCollisionEnter2D(Collision2D col)
     {
         if (col.transform.CompareTag("Player"))
             col.transform.position = spawnPoint.position;
     }
 }
 
               Camera:
 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class FollowCamera : MonoBehaviour{
     
     public Transform target;
     public float smoothSpeed = .3f;
 
     private Vector3 currentVelocity;
 
     void LateUpdate (){
         if (target.position.y > transform.position.y)
         {
             Vector3 newPos = new Vector3(transform.position.x, target.position.y, transform.position.z);
             transform.position = Vector3.SmoothDamp(transform.position, newPos, ref currentVelocity, smoothSpeed * Time.deltaTime);
         }
 
     }
 }
 
               any idea how I can implement a camera position resent upon death? I can't figure it out for the life of me haha
Answer by MT369MT · Aug 12, 2018 at 02:08 PM
Hi, simply get the Main Camera and change its position
      void OnCollisionEnter2D(Collision2D col)
      {
          if (col.transform.CompareTag("Player"))
              col.transform.position = spawnPoint.position;
              Camera.main.transform.position = new Vector3(spawnPoint.position.x, spawnPoint.position.y, -10);
      }
 
              thanks for your help! That brings the camera back which is exactly what I need, however the follow camera script is not re started and so the camera stays in that position, how can I sort this? :)
Why does the script stop? Do you deactivate it or something? I tried the code and after bringing back player and camera the script still works.
it seems as though it repositions the y axis perfectly but the x axis is of to the right, I'm messing around with it now so hopefully ill manage to get it to how it was
Your answer