• 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 Der_Kevin · Jun 28, 2016 at 01:07 PM · getcomponentinheritance

get public int from Script that is in the Plugins Folder?

Hey! Ive got this Script on my character:

 using System.Collections;
 using UnityEngine;
 
 namespace RootMotion.Demos {
     
    public class UserControlMelee : UserControlThirdPerson {
 
         public KeyCode hitKey;
 
         public override void Update () {
             base.Update();
 
             state.actionIndex = Input.GetKey(hitKey)? 1: 0;
         }
     }
 }
 

which Inheriting from this Script:

 using UnityEngine;
 using System.Collections;
 using Rewired;
 
 namespace RootMotion.Demos {    


public class UserControlThirdPerson : MonoBehaviour {

         // Input state
         public struct State {
             public Vector3 move;
             public Vector3 lookPos;
             public bool crouch;
             public bool jump;
             public int actionIndex;
         }
 
         public bool walkByDefault;        // toggle for walking state
         public bool canCrouch = true;
         public bool canJump = true;
 
         public State state = new State();            // The current state of the user input
 
         protected Transform cam;                    // A reference to the main camera in the scenes transform
 
         public int playerId = 0; // The Rewired player id of this character
         private Player player; // The Rewired Player
 
         void Start () {
             // get the transform of the main camera
             cam = Camera.main.transform;
         }
 
         void Awake ()
         {
             // get the transform of the main camera
             player = ReInput.players.GetPlayer(playerId);
             //cam = Camera.main.transform;
         }
 
         public virtual void Update () {
             // read inputs
             state.crouch = canCrouch && Input.GetKey(KeyCode.C);
             state.jump = canJump && Input.GetButton("Jump");
 
             float h = player.GetAxisRaw("Horizontal");
             float v = player.GetAxisRaw("Vertical");
             
             // calculate move direction
             state.move = Quaternion.LookRotation(new Vector3(cam.forward.x, 0f, cam.forward.z).normalized) * new Vector3(h, 0f, v).normalized;
 
             bool walkToggle = Input.GetKey(KeyCode.LeftShift);
 
             // We select appropriate speed based on whether we're walking by default, and whether the walk/run toggle button is pressed:
             float walkMultiplier = (walkByDefault ? walkToggle ? 1 : 0.5f : walkToggle ? 0.5f : 1);
 
             state.move *= walkMultiplier;
             
             // calculate the head look target position
             state.lookPos = transform.position + cam.forward * 100f;
         }
     }
 }
 
 

and i want to get the "public int playerId = 0; // The Rewired player id of this character" from another script

so i thought it would somehow work like this:

 public class myclass : MonoBehaviour {
 
 public int playerNr;
     
     void Update () {
         if(Input.GetKeyDown(KeyCode.E) && isPlayerVisible){
                 playerNr = Player.GetComponent<UserControlMelee>().playerId;
         }
     }
 
 }
 
 

but the first two Scripts here (UserControlMelee and UserControlThirdPerson) are inside the "Plugins" folder which i think thats why i cant access the UserControlMelee component, right?

whats the solution for this beside putting the two scripts outside the plugins folder?

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
0
Best Answer

Answer by Bunny83 · Jun 28, 2016 at 01:34 PM

No, having the scripts inside the plugins folder shouldn't be a problem in this case. Those two classes are inside the "RootMotion.Demos" namespace. Do you import that namespace inside your script where the "myclass" class is defined?

You need a

 using RootMotion.Demos;

at the top of your file in order to use the "UserControlMelee" class. An alternative is to use the full class name:

 playerNr = Player.GetComponent<RootMotion.Demos.UserControlMelee>().playerId;
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 Der_Kevin · Jun 28, 2016 at 02:23 PM 0
Share

ahh, right. its been a long day. thanks man :)

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

44 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 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 do I access a script component added to a gameobject from an assembly at run-time 0 Answers

Why Doesn't Getcomponent add script to game objects inspector automaticly? 1 Answer

Inventory / inhertance driving me insane - help with theory please. 1 Answer

How do I reference a generic BaseClass using GetComponentInParent<>() 2 Answers

Is it possible to set variables for classes? 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