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
-1
Question by NIMACHI · Sep 05, 2017 at 09:06 PM · transformposition

does not work check if dead

I have a check in my code: if(transform.position.y <= cameraTrans.position.y - 6f) but this check doesnt work. help me please

Comment
Add comment · Show 4
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 hulahoolgames · Sep 05, 2017 at 10:20 PM 0
Share

Will need more information, can you post some more code and info on what is happening?

avatar image NIMACHI hulahoolgames · Sep 05, 2017 at 11:07 PM 0
Share

Of cource! there is a code. If the player leaves the camera at a height of - 6f isDead = true; game$$anonymous$$anagerScript.GameOver ();

 using UnityEngine;
 
 public class PlayerController : $$anonymous$$onoBehaviour {
 
     public Transform cameraTrans;
 
     public Game$$anonymous$$anager game$$anonymous$$anagerScript;
 
     public int score = 0;
 
     float playerFirstYPos;
 
     [SerializeField]
     float moveSpd;
 
     [SerializeField]
     float jumpPower;
 
     Rigidbody2D myRigidbody2d;
     SpriteRenderer mySpriteRenderer;
 
     bool isDead = false;
 
     void Awake(){
         
         myRigidbody2d = GetComponent<Rigidbody2D> ();
         mySpriteRenderer = GetComponent<SpriteRenderer> ();
     }
 
     void Start(){
 
         playerFirstYPos = transform.position.y;
 
     }
 
     void Update(){
 
         FlipCharacter ();
         CheckIfDead ();
         SetScore ();
     }
 
     void FixedUpdate (){
 
         Vector3 pos = myRigidbody2d.position;
 
 
 
         pos.x = $$anonymous$$athf.Clamp (pos.x, -2f, 2f);
 
         myRigidbody2d.position = pos;
         //if delete go control touch
         myRigidbody2d.AddForce (Vector2.right * Input.GetAxis ("Horizontal") * moveSpd);
         //if delete go control touch
         if (Input.touchCount > 0)
         {
             Touch touch = Input.GetTouch(0);
             float middle = Screen.width / 2;
             if (touch.position.x < middle)
             {
                 myRigidbody2d.AddForce (Vector2.right * -1 * moveSpd);
                 mySpriteRenderer.flipX = true;
             }
             else if (touch.position.x > middle)
             {
                 myRigidbody2d.AddForce (Vector2.right * 1 * moveSpd);
                 mySpriteRenderer.flipX = false;
             }
         }
         else
         {
             
         }
             
 
     }
 
     void OnCollisionEnter2D(Collision2D col){
 
         if(col.gameObject.CompareTag("Jumpable")){
             
         myRigidbody2d.velocity = new Vector2 (myRigidbody2d.velocity.x, 0f);
         myRigidbody2d.AddForce (Vector2.up * jumpPower);
     }
     }
 
 
     void FlipCharacter(){
 
         if (Input.GetAxisRaw ("Horizontal") < 0)
             mySpriteRenderer.flipX = true;
         else if (Input.GetAxisRaw ("Horizontal") > 0)
             mySpriteRenderer.flipX = false;
 
     }
 
 
     void CheckIfDead(){
         if(transform.position.y <= cameraTrans.position.y - 6f && !isDead) {
             isDead = true;
             game$$anonymous$$anagerScript.GameOver ();
 
         }
     }
 
     void SetScore(){
 
         score = $$anonymous$$athf.$$anonymous$$ax (score, $$anonymous$$athf.FloorToInt (transform.position.y - playerFirstYPos) * 10);
 
     }
 }
avatar image hulahoolgames NIMACHI · Sep 05, 2017 at 11:29 PM 0
Share

Thanks, so does it not enter the if condition in CheckIfDead() or it enters the condition but something else is not working? What is the exact problem?

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by N00MKRAD · Sep 06, 2017 at 07:36 AM

???

We need some info.

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

92 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

Related Questions

Get direction of moving sphere? 1 Answer

What the hell? Cannot convert float to int PROBLEM. 2 Answers

Sprite changing position when button pressed 1 Answer

Discrepancy Between Editor and Build World Transform Positions 1 Answer

How to change a prefab position during play mode 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