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 Matelevi12 · Jun 06, 2019 at 08:29 PM · parent-childrestart game

Parent and Child objects after Restart the game

So my probelm is the Staff whitch is a Child object of the Player object. Its work fine its flip if i flip my Player, BUT after i restart the game while the game is runing a Staff is wont work properly. I really need help i spent 1 day to try to fix that. I just dont get it why its work when i start the game and not if i restart. alt text

This is when i start the game and alt text

This is when i restart. My code looks like this rigth now:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.UI;
 using TMPro;
 using UnityEngine.SceneManagement;
 
 public class PlayerController : MonoBehaviour
 {
     public float speed;
     private Rigidbody2D rb;
     private Vector2 moveVelocity;
     Animator anim;
     int move = Animator.StringToHash("Move");
 
     public GameObject staff;
 
     public SpriteRenderer StaffSprite;
     
     public Vector3 minCameraPos;
     public Vector3 maxCameraPos;
     public bool bounds;
 
     //UI
     public int HP = 5;
     public TextMeshProUGUI Hptext;
 
     public int Money = 0;
     public TextMeshProUGUI MoneyText;
 
     //Dead
     public GameObject DeadScreen;    
     public bool PlayerIsDead = false;    
     void Start()
     {            
         rb = GetComponent<Rigidbody2D>();
         anim = GetComponent<Animator>();
         transform.parent = staff.transform;
     }    
     private void Reset()
     {
         Time.timeScale = 1;
         PlayerIsDead = false;    
         SceneManager.LoadScene(1);
        // SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
         
     }
     // Update is called once per frame
     void Update()
     {
         //UI
         Hptext.text = "HP: " + HP;
         if(HP == 0)
         {
             Dead();
             DeadScreen.SetActive(true);
             PlayerIsDead = true;
             if (Input.GetKeyDown(KeyCode.R) && PlayerIsDead == true)
             {
                 Reset();
             } 
             }
         MoneyText.text = ""+Money;
             //Movement    
             Vector2 moveInput = new Vector2(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"));
             moveVelocity = moveInput.normalized * speed;  
             Vector3 pos = Camera.main.ScreenToWorldPoint(Input.mousePosition);    
             if (pos.x < gameObject.transform.position.x)
             {
             staff.transform.Rotate(new Vector3(180, 0, 0));
             Debug.Log("Left");    
                 //StaffSprite.flipY = true;  
                 transform.eulerAngles = new Vector2(0, 180);                
             //StaffSprite.transform.Rotate(new Vector2(180, 0));    
             staff.transform.localPosition = new Vector3(0.0675f, -0.065f, -1f);
 
             }
             else
             {
                 Debug.Log("Right");    
                 transform.eulerAngles = new Vector2(0, 0);
                 //StaffSprite.transform.Rotate(new Vector2(0, 0));    
                 //StaffSprite.flipY = false;    
                 staff.transform.localPosition = new Vector3(0.0675f, -0.065f, 1f);    
             }    
             if (bounds)
             {
                 transform.position = new Vector2(Mathf.Clamp(transform.position.x, minCameraPos.x, maxCameraPos.x),
                     Mathf.Clamp(transform.position.y, minCameraPos.y, maxCameraPos.y));
             }    
     }
     void Dead()
     {
         Time.timeScale = 0;
         GameObject.Destroy(staff);
         //gameObject.SetActive(false);
         gameObject.GetComponent<Renderer>().enabled = false;            
     }
     void FixedUpdate()
     {
         rb.MovePosition(rb.position + moveVelocity * Time.fixedDeltaTime);
 
     }
 
     void RotateLeft()
     {
         
         transform.Rotate(Vector3.down * -180);
     }
     void RotateRight()
     {
         transform.Rotate(Vector3.down * 180);
     }
 
     void OnTriggerEnter2D(Collider2D Coin)
     {
         if (Coin.tag == "Coin")
         {    
             Money += 1;
             Debug.Log("Coin picked up");
             Destroy(Coin.gameObject);    
         }
     }
 
 
     
 
 
 
 
 }




2.jpg (221.9 kB)
1.jpg (243.5 kB)
Comment
Add comment · Show 1
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 tormentoarmagedoom · Jun 07, 2019 at 09:06 AM 0
Share

Hello.

Why all that empty lines?... I edited a little your post deleting soooo many empty lines... Please, if posting code, do it easy for us to read... delete all unnecessary lines please...

0 Replies

· Add your reply
  • Sort: 

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

174 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

Related Questions

How do I set the pivot to the exact position as parent object? 0 Answers

Lock rotation of child's specific axis? 0 Answers

Making an object follow another object C# 1 Answer

When animator activated child object flies or stops? 0 Answers

Restart Game with Video Ads of Appodeal 1 Answer


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