public void SetControllable(PlayerControllable controllable) { controlling = controllable; controller = controllable.GetComponent <CharacterController>(); if (cameraFollower == null) { cameraFollower = GetComponent <CameraFollower>(); } cameraFollower.target = controllable.cameraTarget; cameraTransform = controllable.cameraTarget.transform; playerStats = controllable.playerStats; if (OnControllableChange != null) { OnControllableChange(controllable); } }
protected override void OnControllableChange(PlayerControllable controllable) { carSphereRB = controllable.GetComponent <CarController>().carSphere.GetComponent <Rigidbody>(); }
void SetControllable(PlayerControllable c) { controllable = c; playerStats = c.GetComponent <PlayerStats>(); OnControllableChange(c); }
// Update is called once per frame void Update() { List <PlayerControllable> allTheBees = FindObjectsOfType <PlayerControllable>().ToList(); if (controlling == null) { if (allTheBees.Count > 0) { int index = allTheBees.IndexOf(controlling); index = (allTheBees.Count + index - 1) % allTheBees.Count; SetControllable(allTheBees[index]); } else { // TODO DEATH return; } } if (controlling != null && controller == null) { controller = controlling.GetComponent <CharacterController>(); } // Build the context for an action context.hovered = GetHoveredGameObject(); context.actor = controlling; context.controller = controller; // Perform controller actions foreach (string input in actionRegister.Keys) { // Add individual input values to context float inputVal = Input.GetAxisRaw(input); context.inputValue = inputVal; // Is button being held? Prepare the action if (Mathf.Abs(inputVal) > 0) { actionRegister[input].hold.Invoke(); } // Was the button pushed down? Trigger immediate behaviour if (Input.GetButtonDown(input)) { actionRegister[input].down.Invoke(); } // Is the button released? Finish the action if (Input.GetButtonUp(input)) { actionRegister[input].up.Invoke(); } } if (!overrideDefaultControls) { if (controlling != null) { direction = new Vector3(); if (Input.GetKey(KeyCode.W)) { direction += Vector3.forward; } if (Input.GetKey(KeyCode.S)) { direction += Vector3.back; } if (Input.GetKey(KeyCode.A)) { direction += Vector3.left; } if (Input.GetKey(KeyCode.D)) { direction += Vector3.right; } direction.Normalize(); Vector3 translationWorldSpace = direction * speed * Time.deltaTime; Vector3 translationCameraSpace = cameraTransform.TransformDirection(translationWorldSpace); controller.Move(translationCameraSpace); controller.Move(Vector3.down * (controller.transform.position.y - controlling.LockHeight)); } } }
protected override void OnControllableChange(PlayerControllable controllable) { staticOffset = controllable.cameraStaticOffset; carSphere = controllable.GetComponent <CarController>().carSphere; }