- Home /
Too subjective and argumentative
C# How to have weapon pickup
I wanted to ask how i can have weapon pick up when i go over the weapon, whenever i try he does go over the weapon but when i press the equip button nothing happens
because you have way too many reputation points to be asking such a question.
@gregzo Dude you can't give a thumbs down based on someone's karma points. He only has 190 anyway. Why waste 2 of your own karma points to vote someone down for a ridiculous reason. I have over 6,000 and I still am learning, just like most people here. If you don't have something constructive or you're not asking for more information on the topic because you're willing to help, don't even comment.
I'm trying to renew my reputation here on UA, but I kinda agree with @gregzo on this one (in principle, not the reason for action). As clunk47 first rightly pointed out, the question is vague and uninformative. This is the type of question I used to immediately close. $$anonymous$$y generic post is :
Sorry, but your question is not suitable for Unity Answers. Please use the Unity Forum for discussions such as "How to ...". Unity Answers is here to help you solve any specific problems you have.
If you submit your code when asking a question, we can see what you are trying to do and help from there.
But as one user told me recently, no-one here likes me, so please ignore this comment, I'm really not an a***hole (really!)
@Josh1231 , please consider editing your question with a better description of your problem and what you're trying to achieve, and include the code you have posted as a comment.
You are correct, I was very vague in explaining my reasons for assessing it as such. I feel my credibility slipping further away....
You have a good point clunk47, made me think hard about giving reasons. Honestly, result should be directly proportional to effort applied;
@gregzo didn't downvote for its karma alone. It was downvoted because, based on its karma, it should have known better than to ask such a vague question.
...and I think everyone on here has the right to up or down vote anyone else for any reason or no reason at all; it's entirely up to them.
I'll give it a down vote also. Reason : I'm bored.
Answer by Kawaburd · Jul 26, 2013 at 08:10 PM
Normally you'd want to destroy the weapon instance when your PC (or cursor, or whatever you're using) collides with the weapon, then stick a variable representing the weapon data... well, wherever you need it. It depends on so many things (one possible weapon, or many? FPS? RPG? something else?) that without giving more information (or trying it yourself and posting a code snippet), that's about as specific of an answer as you're going to get.
this is what i put, is it correct?:
void OnTriggerEnter(Collider collision) {
if (collision.gameObject.tag == "Gun")
{
print ("Gun Found");
if (Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.E))
{
GunStay gunstay = collision.gameObject.GetComponent<GunStay>();
gunstay.EquipGun(this.gameObject);
}
}
}
there is also this for having the gun in the hands but i don't know how to make it work because i can't do foreach (Transform child in currentHolder):
public void EquipGun (GameObject holder) {
if (equip == false)
{
equip = true;
currentHolder = holder;
}
else
{
equip = false;
currentHolder = null;
}
}
// Update is called once per frame
void Update () {
if (equip == true)
{
GameObject GunStay = GameObject.FindGameObjectWithTag("GunStay");
if (GunStay.networkView.is$$anonymous$$ine)
{
Vector3 GunGo = GunStay.transform.position;
Vector3 temp = transform.position;
temp.x = GunGo.x;
temp.y = GunGo.y;
temp.z = GunGo.z;
transform.position = temp;
}
}
}
I don't think Input.Get$$anonymous$$eyDown
will work in OnTriggerEnter
. This restructured version of your script might work.
private GunStay gunstay;
void OnTriggerEnter(Collider other) {
if (other.gameObject.tag == "Gun")
{
gunstay = collision.gameObject.GetComponent<GunStay>();
}
}
void OnTriggerExit(Collider other) {
if(other.gameObject == gunstay.gameObject ) {
gunstay = null;
}
}
void Update() {
if( gunstay!= null && Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.E) ) {
//Equip your gun here
...
gunstay == null;
}
}
i got an error code: `gunstay' conflicts with a declaration in a child block
ok, now you get downvote from me, for not following advice and and editing the question, and not effectively expressing your setup.