// Called automatically by Unity when the script first exists in the scene. void Awake() { m_Input = GetComponent <PInput>(); m_Animator = GetComponent <Animator>(); m_CharCtrl = GetComponent <CharacterController>(); s_instance = this; }
protected void Update() { Vector2 look = PInput.GetLook(); transform.Rotate(Vector3.up * look.x * _lookSpeed * Time.deltaTime, Space.World); Vector2 move = PInput.GetMove(); Vector3 offset = new Vector3(move.x, 0, move.y) * _moveSpeed * Time.deltaTime; transform.position += transform.rotation * offset; _device.text = PInput.IsUsingGamepad ? "Using Gamepad" : "Using Keyboard & Mouse"; bool inputThisFrame = false; for (int i = 0; i < System.Enum.GetValues(typeof(PAction)).Length; i++) { if (PInput.GetInputDown((PAction)i)) { if (_reachedMaxHistory) { _historyStrings.RemoveAt(0); } if (inputThisFrame) { _historyStrings.Add(" (+) " + ((PAction)i).ToString() + "\n"); } else { _historyStrings.Add(Time.frameCount + " " + ((PAction)i).ToString() + "\n"); } inputThisFrame = true; if (_reachedMaxHistory == false) { _reachedMaxHistory = _historyStrings.Count >= MAX_HISTORY_COUNT; } } } if (inputThisFrame) { StringBuilder historyText = new StringBuilder(); foreach (string str in _historyStrings) { historyText.Append(str); } _history.text = historyText.ToString(); } }
void Awake() { m_AttackInputWait = new WaitForSeconds(k_AttackInputDuration); if (s_Instance == null) { s_Instance = this; } else if (s_Instance != this) { throw new UnityException("There cannot be more than one PlayerInput script. The instances are " + s_Instance.name + " and " + name + "."); } }
public static void SwitchInput(int player) { PInput pInput = null; if (player == 1) { pInput = Instance.hairPlayer.GetComponent <PInput>(); pInput.UsesJoystick = !pInput.UsesJoystick; } else if (player == 2) { pInput = Instance.humanPlayer.GetComponent <PInput>(); pInput.UsesJoystick = !pInput.UsesJoystick; } }
public static void RegisterInputAction(PInput input, PInputType type, System.Action <float> action) { List <PlayerInputSender> inputListeners = senders.FindAll(o => o.InputType == input); if (inputListeners.Count > 0) { foreach (PlayerInputSender pis in inputListeners) { pis.setup(type, action); } } else { Debug.Log("No input senders of such type: " + input.ToString()); } }
private void Start() { pm = GetComponent <PlayerMove>(); pg = GetComponent <PlayerGrab>(); pi = GetComponent <PInput>(); spriteRenderer = GetComponent <SpriteRenderer>(); GameObject panel = GameObject.Find("Panel"); for (var i = 0; i < panel.transform.childCount; i++) { hearts.Add(panel.transform.GetChild(i).gameObject); } hp = maxHP; immortalId = TimerManager.Create(2.25f, this); }
public override void FixedUpdate() { if (PInput != null) { PInput.FixedUpdate(); MoveSteer(PInput.XY); UpdateSpeed(); UpdateTail(); //UpdatePositionSphere(); /* * if (Input.GetKeyDown(KeyCode.X)) * AddTailPart(); * * if (Input.GetKeyDown(KeyCode.L)) * Dive(); */ } }
// Start is called before the first frame update void Start() { pm = GetComponent <PlayerMove>(); pg = GetComponent <PlayerGrab>(); pi = GetComponent <PInput>(); pm.enabled = false; pg.enabled = false; pi.enabled = false; earth = GameObject.Find("Earth").GetComponent <EarthGoDown>(); Debug.Log("Animate"); animator = GetComponent <Animator>(); rb = GetComponent <Rigidbody2D>(); transform.localScale = new Vector3(-0.3f, 0.3f, 1); rb.velocity = new Vector2(5, 0); animator.SetTrigger("Walk"); }
/*PID*/ private async void SendPID_Click(object sender, RoutedEventArgs e) { //Send PID coefficients to Oven SendPID.IsEnabled = false; PID hmi = (PInput.ValueFloat(), IInput.ValueFloat(), DInput.ValueFloat()); PID psoc = await Oven.SetPID(hmi); if (psoc == hmi) { POven.Text = psoc.Proportional.ToString(); IOven.Text = psoc.Integral.ToString(); DOven.Text = psoc.Derivative.ToString(); await ShowSuccess("PID updated successfully"); Settings[nameof(PID)] = psoc.ToString(); } SendPID.IsEnabled = true; }
private void Init() { stats = PlayerParameters.Instance; m_PInput = gameObject.AddComponent <PInput>(); m_PInput.Init(this); m_PMove = gameObject.AddComponent <PMove>(); m_PMove.Init(this); m_PCamera = gameObject.AddComponent <PCamera>(); m_PCamera.Init(this); m_PShoot = gameObject.AddComponent <PShoot>(); m_PShoot.Init(this); m_PUI = gameObject.AddComponent <PUI>(); m_PUI.Init(this); }
public void Initalize(int playerIndex, PlayerProperties playerProperties, PlayerCamera playerCamera, GameManager gameManager) { m_PlayerIndex = playerIndex; m_PlayerProperties = playerProperties; Camera = playerCamera; m_GameManager = gameManager; // Assign properties m_Controller = m_PlayerProperties.Controller; m_TankProperties = m_PlayerProperties.Tank; // Initalize input PInput.Initalize(m_PlayerProperties.Controller, playerProperties.InputType); // Initalize health Health.InitalizeHealth(m_TankProperties.MaxHealth); Health.DeathEvent += OnDeath; Health.DamageEvent += OnDamage; // Initalize weapon Weapon.SwitchWeapon(playerProperties.Tank.DefaultWeapon); StartCoroutine(ReadWheelHits()); // Wheels WheelCollider[] wheels = transform.GetComponentsInChildren <WheelCollider>(); m_WheelsLeft = new List <WheelCollider>(); m_WheelsRight = new List <WheelCollider>(); foreach (WheelCollider wheel in wheels) { string parent = wheel.transform.parent.name.ToLower(); if (parent.Contains("left")) { m_WheelsLeft.Add(wheel); } if (parent.Contains("right")) { m_WheelsRight.Add(wheel); } } m_TireLeft = transform.Find("Mesh/TireLeft"); m_TireRight = transform.Find("Mesh/TireRight"); // Set the layer masks MeshRenderer[] meshObjects = transform.GetComponentsInChildren <MeshRenderer>(); UpdatePlayerLayerMasks(meshObjects, playerIndex); // Find and store all particle systems ParticleSystem[] particleSystems = transform.GetComponentsInChildren <ParticleSystem>(); m_ParticleSystems = new Dictionary <ParticleType, ParticleSystem>(); m_ParticleEmission = new Dictionary <ParticleType, float>(); foreach (ParticleSystem p in particleSystems) { foreach (ParticleType type in (ParticleType[])Enum.GetValues(typeof(ParticleType))) { if (p.transform.name.Contains(type.ToString())) { m_ParticleSystems.Add(type, p); m_ParticleEmission.Add(type, 0.0f); break; } } } // JumpThruster m_JumpThruster = transform.Find("Mesh/JumpThruster"); m_JumpThrusterDefaultPos = m_JumpThruster.localPosition; m_JumpThrusterAnimationTimer = 9999.0f; }