• 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
Question by bitthebillias · Jan 23, 2019 at 08:13 PM · scripting probleminputcontrols

Clicking won't throw object

So when i am ingame, i can't get this object to be thrown, it just tells me that there is no input set up for it. I can pick it up because i added an input for that, but i don't understand how to edit the other button inputs to get them to work.

how do i get them to work properly?

Any thoughts will help! thanks!!

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class ThrowObject : MonoBehaviour
 {
 
     public Transform player;
     public Transform PlayerCam;
     public float throwForce = 10;
     bool hasPlayer = false;
     bool beingCarried = false;
     public AudioClip[] soundToPlay;
     private AudioSource audio;
     public int dmg;
     private bool touched = false;
 
     // Start is called before the first frame update
     void Start()
     {
         audio = GetComponent<AudioSource>();
     }
 
     // Update is called once per frame
     void Update()
     {
         float dist = Vector3.Distance(gameObject.transform.position, player.position);
         if (dist <= 2.5f)
         {
             hasPlayer = true;
         }
         else
         {
             hasPlayer = false;
         }
         if (hasPlayer && Input.GetButtonDown("Use"))
         {
             GetComponent<Rigidbody>().isKinematic = true;
             transform.parent = PlayerCam;
             beingCarried = true;
         }
         if (beingCarried)
         {
             if(touched)
             {
                 GetComponent<Rigidbody>().isKinematic = false;
                 transform.parent = null;
                 beingCarried = false;
                 touched = false;
             }
             if (Input.GetMouseButtonDown(0))
             {
                 GetComponent<Rigidbody>().isKinematic = false;
                 transform.parent = null;
                 beingCarried = false;
                 GetComponent<Rigidbody>().AddForce(PlayerCam.forward * throwForce);
                 RandomAudio();
             }
             else if (Input.GetMouseButtonDown(1))
             {
                 GetComponent<Rigidbody>().isKinematic = false;
                 transform.parent = null;
                 beingCarried = false;
             }
         }
     }
     void RandomAudio()
     {
         if (audio.isPlaying)
         {
             return;
         }
         audio.clip = soundToPlay[Random.Range(0, soundToPlay.Length)];
         audio.Play();
     }
     void OnTriggerEnter()
     {
         if (beingCarried)
         {
             touched = true;
         }
     }
 }
 
 

alt text

alt text

screen-shot-2019-01-23-at-31053-pm.png (27.9 kB)
screen-shot-2019-01-23-at-30717-pm.png (24.4 kB)
Comment

People who like this

0 Show 0
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

2 Replies

  • Sort: 
avatar image
Best Answer

Answer by xxmariofer · Jan 23, 2019 at 08:19 PM

Hello, can you open one of those buttons tab? and share a screenshot? probably they have nothing set in the Positive Button property.

Comment
bitthebillias

People who like this

1 Show 0 · 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

Answer by bitthebillias · Jan 23, 2019 at 10:05 PM

alt text

I think this is what you were talking about, if not please let me know!


screen-shot-2019-01-23-at-32338-pm.png (54.8 kB)
Comment

People who like this

0 Show 6 · 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 xxmariofer · Jan 23, 2019 at 10:23 PM 0
Share

Hello you need to assig a positive and or negative button, that will be the button that will fire the input, open the horizontal and vertical axis and check how they do have the positive and negative field assign with the buttons or keys that will fire the input.

avatar image bitthebillias xxmariofer · Jan 23, 2019 at 10:57 PM 0
Share

so i gave that a shot. the left click works now, but for whatever reason, the throw option doesn't seem to work. it just drops like the right click. thoughts?

avatar image xxmariofer bitthebillias · Jan 23, 2019 at 11:03 PM 0
Share

what do you mean by the throw option?

Show more comments

Unity Answers is in Read-Only mode

Unity Answers content will be migrated to a new Community platform and we are aiming to launch a public beta by June 9. Please note, Unity Answers is now in read-only so we can prepare for the final data migration.

For more information and updates, please read our full announcement thread in the Unity Forum.

Follow this Question

Answers Answers and Comments

182 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Toggle between Touch input and accelerometer 0 Answers

Single tap / Double tap / Hold button 0 Answers

I need help with a Controller on a 2D Game for Android with horizontal movement 1 Answer

Is there a way to assign multiple set control schemes to gameobjects at run time for local multiplayer keyboard controls? 0 Answers

Controls inverted on my character controller 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