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 Marca59 · Jan 14, 2018 at 01:43 PM · score system

need help wih score system

my player has two scripts to move, one is to move the horse and the other to move the hand for a spear, on this script i want to make my score adds when the spear collides with the gameobject.

in my project I have one gameobject, and in this gameobject I have four target, 2 object is 1 poin, 1 target is one point and last is 3 point, I need help with this.

this script I need put in hand because this script is for hand movement, in hand is spear when I put game objects in project and spear is collide nothing happens.

 using UnityEngine;
 using UnityEngine.UI;
 using System.Collections;
 
 public class PlayerController : MonoBehaviour
 {
     public Text countText;
     private int count;
 
     void start ()
     {
         count = 0;
         SetCountText ();
     }
     void Update()
     {
         var z = Input.GetAxis("Mouse Y") * Time.deltaTime * 3.0f;
 
         transform.Rotate(0, 0, z);
         transform.Translate(0, 0, z);
     }
         
         void OnTriggerEnter(Collider other)
         {
         if (other.gameObject.CompareTag("Pick Up"))
     {
         other.gameObject.SetActive (false);
         count = count + 1;
         SetCountText ();
     }    
 }
 
     void SetCountText ()
     {
         countText.text = "Count: " + count.ToString ();
     }
 }
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

4 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by efeguclu · Jan 14, 2018 at 03:00 PM

First, check if you selected isTrigger in your pickup's collider component if you didn't, select it Then, if this script is attached to your hand you have to attach another script in your spear's inspector and add all of this script instead void Update() into another script replace void start() to void Start() I made script changes for you :

 using UnityEngine;
  using UnityEngine.UI;
  using System.Collections;
  
  public class SpearController : MonoBehaviour
  {
      public Text countText;
      private int count;
  
      void Start ()
      {
          count = 0;
          SetCountText ();
      }
          
          void OnTriggerEnter(Collider other)
          {
          if (other.gameObject.CompareTag("Pick Up"))
      {
          other.gameObject.SetActive (false);
          count = count + 1;
          SetCountText ();
      }    
  }
  
      void SetCountText ()
      {
          countText.text = "Count: " + count.ToString ();
      }
  }

and here is your handScript :

  using UnityEngine;
  using UnityEngine.UI;
  using System.Collections;
  
  public class PlayerController : MonoBehaviour
  {
      void Update()
      {
          var z = Input.GetAxis("Mouse Y") * Time.deltaTime * 3.0f;
  
          transform.Rotate(0, 0, z);
          transform.Translate(0, 0, z);
      }
  }
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
avatar image
1

Answer by unity_INzTEchDYxPHAQ · Jan 15, 2018 at 11:42 AM

Add a rigidbody on one of the interacting objects, the rigidbody must not be set to kinematic. I'd suggest putting it on the spear.

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 Marca59 · Jan 19, 2018 at 11:57 AM 0
Share

thanks work with rigidbody

 using UnityEngine;
   using UnityEngine.UI;
   using System.Collections;
   
   public class SpearController : $$anonymous$$onoBehaviour
   {
       private Rigidbody rb;
       public Text countText;
       private int count;
   
       void Start ()
       {
           rb = GetComponent<Rigidbody>();
           count = 0;
           SetCountText ();
       }
           
           void OnTriggerEnter(Collider other)
           {
           if (other.gameObject.CompareTag("Pick Up"))
       {
           other.gameObject.SetActive (false);
           count = count + 1;
           SetCountText ();
       }    
   }
   
       void SetCountText ()
       {
           countText.text = "Count: " + count.ToString ();
       }
   }
avatar image
0

Answer by Marca59 · Jan 15, 2018 at 11:12 AM

same thing, I am put this scripts and when collide with gameobject with tag Pick Up nothing happens.

test picture: alt text


1.png (418.8 kB)
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
avatar image
0

Answer by SavaTim · Jun 13, 2019 at 02:06 PM

it Can Halp https://youtu.be/d547eh7jqaM

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

76 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

Related Questions

How do I use PlayerPrefs to save My Score? 2 Answers

I am having trouble making a High score system. I am trying to write the the top 5 highscores to a file and cannot use PlayerPrefs ,I need help with a high score system 0 Answers

How do I change variable value in other script, so my UI score will be 0 1 Answer

Unable to show button after an event 0 Answers

Score doesn't start with 0 at the begging of the game 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