Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Manacraft05 · Dec 28, 2018 at 01:00 PM · cameraplayercamera-movementissuex-axis

Don'tDetroyOnLoad | issue

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

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by ray2yar · Dec 28, 2018 at 02:11 PM

How many cameras are in the scene? Just one? Is it following just one player or both? Your camera script is written to follow whatever transformplane is... so, change it to the player you want it to follow.

I suggest reworking your scripts so that you don't have all players being flagged as "don't destroy on load"... instead maybe have a gamemanager persist between scenes that holds player data and spawns the players if they aren't dead. However, if you must have players persist, don't destroy them by script. Instead have them turn off their certain components (like colliders). Then when a new scene loads add a listener and have it check if the player died in the previous scene.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

172 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How can I get a Capsule to move and rotate in the direction the cam is facing? 1 Answer

Camera follow player with code 3 Answers

How to get camera to follow player 2d 11 Answers

Issues with player prefabs when I try to teleport it 1 Answer

How can I keep a player inside the camera box? [C#] 3 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges