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 Paratrooper82 · Jan 28, 2018 at 08:23 PM · gameobjecttriggerreset

Reset GameObject with trigger on respawn

Hey guys and girls. So I made a trap. The trap is a sprite that is a weight, to this weight I have attached my "hurtPlayer" script, which works fine.

On the bottom I have my spring board with a script that makes the weight fall down and then hurt the player. The board on the bottom has a boxColldier2D with a trigger. I have to attach my weight gameObject to the script on the sprinboard to make it work.

I also have a resetOnRespawn script that literally works for all my enemies and even this weight. However what happens is when I respawn the trigger to the weight is activated again and the weight falls right when I am respawning. Is there a way to fix this, so it doesn't just fall when I am respawning?

alt text

CODE FOR TRAP: using System.Collections; using System.Collections.Generic; using UnityEngine;

 public class FallingTraps : MonoBehaviour {
 
     public GameObject fallingTrap; 
 
 
 
     // Use this for initialization
     void Start () {
 
     }
     
     // Update is called once per frame
     void Update () {
 
     }
 
     void OnTriggerEnter2D(Collider2D other){
 
         if (other.tag == "Player") {
 
             //GameObject.FindWithTag ("FallingTrap").GetComponent<Rigidbody2D> ().isKinematic = false; 
 
             fallingTrap.GetComponent<Rigidbody2D> ().isKinematic = false;
         } 
     }
 }

And RESET ON RESPAWN SCRIPT: using System.Collections; using System.Collections.Generic; using UnityEngine;

 public class ResetOnRespawn : MonoBehaviour {
 
     private Vector3 startPosition; 
     private Quaternion startRotation;
     private Vector3 startLocalScale; 
 
     private Rigidbody2D myRigidBody; 
 
 
 
     // Use this for initialization
     void Start () {
 
         startPosition = transform.position;
         startRotation = transform.rotation;
         startLocalScale = transform.localScale;
 
         if(GetComponent<Rigidbody2D>() != null){
             myRigidBody = GetComponent<Rigidbody2D> ();
         }
     }
     
     // Update is called once per frame
     void Update () {
 
 
 
     }
 
     public void ResetObject(){
 
         transform.position = startPosition; 
         transform.rotation = startRotation;
         transform.localScale = startLocalScale; 
 
         if (myRigidBody != null) {
 
             myRigidBody.velocity = Vector3.zero; 
 
         }
 
     }
 }
trap-picture.png (86.0 kB)
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
1
Best Answer

Answer by Commoble · Jan 28, 2018 at 08:25 PM

When you activate the trap, you're activating it by setting its rigidbody.isKinematicto false, so you'll need to set it back to true when you reset it.

Comment
Add comment · Show 1 · 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 Paratrooper82 · Jan 30, 2018 at 02:58 AM 0
Share

Thank you so much! :) It worked.

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

170 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

Related Questions

Trigger Sets GameObject 0 Answers

Unity 2019 can't change/access GameObject Variables from another script 0 Answers

2D Power up script not working 0 Answers

How to become invincible towards enemies when powerup is active 2 Answers

how would i make something pop out from behind a corner then pop back like the Bendy cutouts from Bendy and The Ink Machine 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