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?
ahh, right. its been a long day. thanks man :)
– Der_Kevin