• Unity
  • Services
  • Made with Unity
  • Learn
  • 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
  • Forums
  • Answers
  • Feedback
  • Issue Tracker
  • Blog
  • Evangelists
  • User Groups

Navigation

  • Home
  • Unity
  • Industries
  • Made with Unity
  • Learn
  • Community
    • Forums
    • Answers
    • Feedback
    • Issue Tracker
    • Blog
    • Evangelists
    • User Groups
  • Get Unity
  • Asset Store

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 bitthebillias · Jan 23 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
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

2 Replies

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

Answer by xxmariofer · Jan 23 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
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 bitthebillias · Jan 23 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
Add comment · 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 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 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 at 11:03 PM 0
Share

what do you mean by the throw option?

Show more comments

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

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

Related Questions

Touch Controls for a 2D ball game 0 Answers

How do I get MonoDevelop, because visual studio keeps opening? 2 Answers

ps3 controller messed up the normal controls 1 Answer

Use Standard Assets Mobile Input Script 0 Answers

Changing controls from keyboard to touch in the game 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges