Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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
0
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
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

1 Reply

· Add your reply
  • Sort: 
avatar image
1
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

Comment
Add comment · Show 7 · 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 Josh1231 · Jul 25, 2013 at 11:58 AM 0
Share

thank you, this helped lots

avatar image amphoterik · Jul 25, 2013 at 12:10 PM 0
Share

Glad I could help.

avatar image Josh1231 · Jul 25, 2013 at 12:45 PM 0
Share

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

avatar image amphoterik · Jul 25, 2013 at 12:48 PM 0
Share

Is "GunStay" an object that represents the hands?

avatar image Josh1231 · Jul 25, 2013 at 12:51 PM 0
Share

yes it is.

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.

Follow this Question

Answers Answers and Comments

16 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

Related Questions

C# How to have a gun select 1 Answer

How do I send a simple Vector3 over a network? 1 Answer

modernized master server script? 1 Answer

Player object on host can interact with objects, client players cannot. 0 Answers

How to connect to hosted scene (Multiplayer) 2 Answers


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