• 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 /
  • Help Room /
avatar image
0
Question by MarioUnity3d · Nov 15, 2015 at 01:32 PM · namespace

Using 2 different namespaces

I am using 2 different set of codes that both have their own namespaces. One is for a water emulator and one for my custom ThirdPerson Controller. Now the problem is that i want to create a detector script that when the player enters the water to kill him. As you can imagine i need to somehow use 2 namespaces in that script...because one is 'grabbing' info from the water script and one from the Player's controller. Is there a way i can access both namespace objects in that script ?

 using UnityEngine;
 using System.Collections;
 
 namespace ------WhatToUseHere???-------- (MyWaterSim or ThirdPersonCharacter  namespace)
 {
     public class DetectAndKill : MonoBehaviour
     {
         public WaterSim watersim;
 
         void Update()
         {
               transform.position = new Vector3(transform.position.x, watersim.waterSurface, transform.position.z);
         }
 
         void OnTriggerEnter(Collider other)
         {
             if (other.tag == "Player")
             {
                 ThirdPersonCharacter player = other.GetComponent<ThirdPersonCharacter>();
                 player.die();
             }
         }
     }
 }

The detector will be applied to a gameobject that will change its Y position according to the water surface. Then if the player lands on it...it should send a message to kill the player.

Now i dont want to use the same namespace for both scripts...because if you think about it...i might use in the future another script that uses its own namespace variable...so i cant be doing this every time i add something new to the code....Isnt there an easy way to access both scripts ?

-Thanks

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 Jessespike · Nov 15, 2015 at 01:45 PM

At the top of the script:

 using MyWaterSim;
 using ThirdPersonCharacter;

Now you have access to the scripts in those namespaces. You don't even need to use namespaces, so if you choose to wrap DetectAndKill in a namespace or not, that's entirely up to you.

Comment
Add comment · Show 1 · 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 MarioUnity3d · Nov 15, 2015 at 01:49 PM 0
Share

Awesome :) That was so easy lol..I am such a noob. Thanks!

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

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

33 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

Related Questions

How Can I Make Completely Custom Text Input Objects 1 Answer

Unity won't build on Windows after reinstall 0 Answers

Issues with namespaces and folder structure 1 Answer

A namespace can only contain types and namespace declarations 1 Answer

Where is the namespace UntiyEngine.Windows 1 Answer


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