Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by ToeBeanGames · Oct 13, 2016 at 09:50 PM · c#checkpoint

Help with checkpoint system (C#)

Okay so. I know exactly what I'm trying to do here, and how I'm trying to do it. Pretty much what I have is a checkpoint manager (with DontDestroyOnLoad) and checkpoint objects. When the player hits the checkpoint, it sets the spawn position in the manager to the checkpoint's position. So when the player dies, it's supposed to reload the scene and spawn the player at the new spawn position. Except, what's actually going on is when the player dies after hitting the checkpoint, the manager just spawns them at the beginning of the level (set in the inspector rather than in the script).

Here's the checkpoint manager script:

 using UnityEngine;
 using System.Collections;
 
 public class CheckpointManager : MonoBehaviour {
     
     [SerializeField] Object Player;
 
     public Vector3 pos;
     public Quaternion rot;
 
 
     // Use this for initialization
     public void Awake()
     {
         DontDestroyOnLoad(this);
         if (FindObjectsOfType(GetType()).Length > 1)
             Destroy(gameObject);
 
         Instantiate(Player, pos, rot);
 
         
 
     }
 
 
     // Update is called once per frame
     void Update () {
 
 
 
         Debug.Log ("position = (" + pos.x.ToString ("F0") + "," + pos.y.ToString ("F0") + "," + pos.z.ToString ("F0") + ")");
 
     }
 
     public void Respawn()
     {
         Application.LoadLevel(Application.loadedLevelName);
 
     }
 }

And the checkpoint object script:

 using UnityEngine;
 using System.Collections;
 
 public class CheckpointObject : MonoBehaviour {
 
     Animator anim;
     AudioSource source;
     public AudioClip checkSound;
     public GameObject PointLaser;
     //public int CheckNumber;
     CheckpointManager Manager;
     public bool IsReached;
 
     [SerializeField] bool IsStartPoint;
 
     // Use this for initialization
     void Awake () {
 
         anim = GetComponent<Animator> ();
         source = GetComponent<AudioSource> ();
         Manager = GameObject.FindGameObjectWithTag("Manager").GetComponent<CheckpointManager>();
     
     }
 
     void Start()
     {
         /*
         if (IsStartPoint) {
             Manager.pos = transform.position;
             Manager.rot = transform.rotation;
         }
         */
     }
     // Update is called once per frame
     void Update () {
 
         anim.SetBool("Reached", IsReached);
         if (IsReached)
         {
             PointLaser.SetActive(false);
 
         }
     }
 
     void OnTriggerEnter (Collider col)
     {
         if (!IsStartPoint) {
             if (!IsReached) {
                 if (col.gameObject.tag == "Player") {
                     Manager.pos = transform.position;
                     Manager.rot = transform.rotation;
                     source.PlayOneShot (checkSound);
                     IsReached = true;
                 }
             }
         }
     }
 }
 

I hope someone can help me out here. I don't know why the manager isn't spawning the player at the checkpoint.

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

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Morgenstern_1 · Oct 14, 2016 at 11:32 AM

DontDestroyOnLoad should be set on the gameObject, not the script I think. Try changing that.

But then you'll have a new problem - you can't instantiate the player in Awake because Awake only gets run once. When you reload the scene it will not get called again, so your character won't spawn.

Comment
Add comment · Show 4 · 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
avatar image ToeBeanGames · Oct 14, 2016 at 02:21 PM 0
Share

Actually my problem isn't that it's not spawning the player (it only does that if I move instantiating them to start) the problem is it isn't spawning them in the right spot.

avatar image Morgenstern_1 ToeBeanGames · Oct 14, 2016 at 02:28 PM 0
Share

I understand that, read the first half of my answer. To clarify: DontDestroyOnLoad is not getting set properly, therefore your object might be getting destroyed on load. The new object then spawns the player back at the start. You'll hit my second point once you've fixed that.

avatar image ToeBeanGames Morgenstern_1 · Oct 14, 2016 at 10:46 PM 0
Share

Okay, I see what you're getting at.

I moved the awake parts to start and fixed DontDestroyOnLoad but it's still not spawning the player at the checkpoint.

Show more comments
avatar image
-1

Answer by cartersupergames · Sep 12, 2021 at 08:26 PM

Guys Guys Guys, youre doing it all wrong, Just use the function Teleport, like this: Teleport(Gameobject Nameofplayer) 65,574433 75,68765 824,754 Its simple.

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

246 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 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

Help with Checkpoint (C#) 1 Answer

Making a counter that does not reflect on time 2 Answers

OnTriggerEnter has a weird bug, help me pls 1 Answer

Stopping an animation when key is unpressed 0 Answers

Check rotation of an obstacle 0 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