- Home /
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;
}
}
}
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.
Answer by bitthebillias · Jan 23, 2019 at 10:05 PM
I think this is what you were talking about, if not please let me know!
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.
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?