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 /
avatar image
0
Question by AndrewBrown123 · Jun 18, 2018 at 02:21 PM · triggerpositiongetcomponentbool

Object will not return to start position after player respawns

Hello, I'm stuck on a part of my code for a object that fly's towards you after you trigger it to. The object has collider on it that is used for a trigger and a child object on it that uses my Respawn Script to reset the player when it touches the object that too has a collider. My question is that I can't make it return to the start position after it made it to it's target position. I know that isDead is not being triggered because there's no condition to tell it to be true if something happens but I can't figure out how I would write it out in code to make it know when the play hits the collider with the Respawn Script on it makes the object go back to it's start position.

Thank You to anyone that helps out.

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class fireWorks : MonoBehaviour {
 
     public Transform target;//Go to this position
     public Transform returnTarget;//Go back to start position
     public float speed;//speed it travels at
     public bool setOff;
     public bool isDead;
     public Respawn myRespawn;
 
     void Start(){
         GameObject.FindWithTag("Firework").GetComponent<Respawn>();
         isDead = false;
     }
 
     void OnTriggerEnter2D(Collider2D other){
         if(other.gameObject.CompareTag("Player")){
             setOff = true;
         }    
     }
 
     void Update(){
         if(setOff){
             float step = speed * Time.deltaTime;
             transform.position = Vector3.MoveTowards(transform.position, target.position, step);
         }
         if(isDead == true){//if dead move back.
             setOff = false;
             float beep = speed * Time.deltaTime;
             transform.position = Vector3.MoveTowards(transform.position, returnTarget.position, beep);
         }
     }
 }
Comment
Add comment · Show 2
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 nomadic · Jun 18, 2018 at 09:10 PM 0
Share

Hi Andrew, can you clarify your question a little bit? It's hard to understand which part you are stuck on. Are you trying to find a Respawn script that is attached to the Player?

avatar image AndrewBrown123 nomadic · Jun 18, 2018 at 09:38 PM 0
Share

The Respawn Script isn't attached to the player character it's attached to a child object on the moving object. Sorry for not being more clear.

If this help here is my Respawn Script.

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class Respawn : $$anonymous$$onoBehaviour {
 
     [SerializeField]
     private Transform player;
     [SerializeField]
     private Transform respawnPoint;
 
     void OnTriggerEnter2D(Collider2D other)
     {
         if(other.gameObject.tag == "Player"){
             Debug.Log("WOR$$anonymous$$!!!");
             player.transform.position = respawnPoint.transform.position;
             //When placing this on a object BOX COLLIDER must be made IS TRIGGER.
         }
     }
 }

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by NoDumbQuestion · Jun 19, 2018 at 02:04 AM

How did you attach myRespawn?

Because in script you find that object but didnt attach it with anything

      public Respawn myRespawn;
  
      void Start(){
          GameObject.FindWithTag("Firework").GetComponent<Respawn>();
          isDead = false;
      }

Did you mean this?

 myRespawn = GameObject.FindWithTag("Firework").GetComponent<Respawn>();
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

119 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

Related Questions

linking particlesystem to cube,conecting particlesystem to cube 0 Answers

getComponent not working with Triggers? 1 Answer

Get bool value from one script to another (C#) 2 Answers

Writing a bool to a separate script without scripts name? 3 Answers

Can you use triggers in script? 2 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