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 Flaco1009 · Oct 13, 2016 at 10:14 PM · objectscomparison

How to compare two objects?

Hello there, I'm having a problem with my game. I want the player when he hits the Keyword T and has the ball in his hands to throw it. My problem what I have it's that even tho the player doesn't have the ball but hits T the Ball respawn in the Y axis like he's accepting the if statement.

I currently have this code in a Update function, there is a picture below that shows you when you press T and the ball respawn on top. I appreciated the help Thank You.

     if(Input.GetKeyDown(KeyCode.T) && player != null)
     {
        
         ball.transform.parent = null;
         ball.transform.position = new Vector3(transform.position.x, transform.position.y + movespeed, 1);
         ball.GetComponent<Collider>().enabled = true;
     }

 }

alt text

errorgame.png (125.5 kB)
Comment
Add comment · Show 3
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 OpenXcell-Studio · Oct 14, 2016 at 06:43 AM -1
Share

insufficient information

avatar image NoseKills · Oct 14, 2016 at 08:22 AM 1
Share

Where are you setting player null to try to prevent this?

avatar image Flaco1009 NoseKills · Oct 14, 2016 at 04:32 PM 0
Share

Hi there thank you for the reply, I think I don't have the player setting to null. I though for default if the player isn't having anything on his hand it will be null. So no I don't have the player = null anywhere if that what you are asking. Here are the codes that I have if you care to view and reply This is where the player does all moving, pressing any $$anonymous$$ey etc:

public class Player$$anonymous$$ovement : $$anonymous$$onoBehaviour {

 [HideInInspector]
 public bool facingRight = true;
 [HideInInspector]
 public bool jump = false;
 public float moveForce = 365f;
 public float maxSpeed = 5f;
 public float jumpForce = 1000f;
 public Transform groundCheckR;

 public Transform groundCheckL;


 private bool groundedL = false;
 private bool groundedR = false;
 private Animator anim;
 private Rigidbody rb2d;

 public GameObject player;
 public GameObject ball;
 public float movespeed = 1.0f;


 // Use this for initialization
 void Awake()
 {
    
     anim = GetComponent<Animator>();
     rb2d = GetComponent<Rigidbody>();
 }

 // Update is called once per frame
 void Update()
 {
     groundedL = Physics.Linecast(transform.position, groundCheckL.position, 1 << Layer$$anonymous$$ask.NameToLayer("Ground"));
     groundedR = Physics.Linecast(transform.position, groundCheckR.position, 1 << Layer$$anonymous$$ask.NameToLayer("Ground"));

     if (Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.Space) && groundedL)
     {
         jump = true; 
     }

     if (Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.Space) && groundedR)
     {
         jump = true;
     }

     if (Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.RightArrow))
     { transform.eulerAngles = new Vector3(0,90,0); }
     if(Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.LeftArrow))
     { transform.eulerAngles = new Vector3(0, -90, 0); }

     if(Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.T) && player.GetInstanceID() != ball.GetInstanceID())
     {
         //ball.GetComponent<Collider>().enabled = true;
         ball.transform.parent = null;
         ball.transform.position = new Vector3(transform.position.x, transform.position.y + movespeed, 1);
         ball.GetComponent<Collider>().enabled = true;
     }

 }

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

77 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

Related Questions

See if function returns a certain gameObject 0 Answers

How to check if any GameObject equals any other GameObject 0 Answers

How should i go about having an object have 2 clickable areas? 2 Answers

UnityScript nested objects best practice 1 Answer

How do i make object when collided be cutted/culled? 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