- Home /
Question by
Josh1231 · Jul 25, 2013 at 11:44 AM ·
c#networkingnetworkequip
C# How to make the gun remember who equipped it
I wanted to know how to make the gun remember who equipped it after it has been equipped. this is what i have so far:
using UnityEngine;
using System.Collections;
public class GunStay : MonoBehaviour {
public bool equip = false;
// Use this for initialization
void Start () {
equip = false;
}
public void EquipGun () {
if (equip == false)
{
equip = true;
}
else
{
equip = false;
}
}
// Update is called once per frame
void Update () {
if (equip == true)
{
GameObject GunStay = GameObject.FindGameObjectWithTag("GunStay");
if (GunStay.networkView.isMine)
{
Vector3 GunGo = GunStay.transform.position;
Vector3 temp = transform.position;
temp.x = GunGo.x;
temp.y = GunGo.y;
temp.z = GunGo.z;
transform.position = temp;
}
}
}
}
Comment
Best Answer
Answer by amphoterik · Jul 25, 2013 at 11:55 AM
I would add a variable to contain the gun holder and modify the EquipGun method to be:
GameObject currentHolder
public void EquipGun (GameObject holder) {
if (equip == false)
{
equip = true;
currentHolder = holder;
}
else
{
equip = false;
currentHolder = null;
}
}
Then in any script that can pick up a gun you would do:
EquipGun(this);
You can find a child element like this:
GameObject GunStay = currentHolder.transform.Find("GunStay");
In your code GunStay is a tag. I am using it like a name. Replace the name GunStay with whatever the object is actually named
how do i make sure it goes to this objects hands ins$$anonymous$$d of another since i don't know how to do a parent check with it