void Load_Players() { //game record holds all player info game_record = FindObjectOfType <In_Game_Record>(); if (game_record != null && tank_prefab != null) { List <Player_Information> all_players = game_record.Get_All_Players(); print(all_players.Count); for (int i = 0; i < all_players.Count; i++) { //load player GameObject player = Instantiate(tank_prefab, Vector3.zero, Quaternion.identity) as GameObject; //assign controller Vehicle_Control_Holder control_holder = player.GetComponentInChildren <Vehicle_Control_Holder>(); if (control_holder != null) { control_holder.Set_Player_Index(all_players[i].player_index); //set colours here } if (control_holder == null) { print("NO CONTROL HOLDER"); } } } else { print("ERROR"); } }
// Update is called once per frame void Update() { if (vehicle_control_holder == null) { vehicle_control_holder = GetComponent <Vehicle_Control_Holder>(); } else { if (Game_State.game_state_inst != null && Game_State.game_state_inst.Get_State() == Game_State.Game_States.in_play) { float hor = vehicle_control_holder.state.ThumbSticks.Left.X; float ver = vehicle_control_holder.state.ThumbSticks.Left.Y; if (hor != 0 || ver != 0) { //Rotate(hor, ver); Move(hor, ver); Rotate(hor, ver); } else { Decelerate(); } } } }
private void Start() { control_holder = GetComponent <Vehicle_Control_Holder>(); renderers = this.gameObject.GetComponentsInChildren <MeshRenderer>(); if (control_holder != null) { print(control_holder.Get_Player_Index()); switch (control_holder.Get_Player_Index()) { case 0: Switch_Colour(new Color(100f / 255, 176f / 255, 88f / 255)); break; case 1: Switch_Colour(new Color(64f / 255, 127f / 255, 127f / 255)); break; case 2: Switch_Colour(new Color(125f / 255, 73f / 255, 141f / 255)); break; case 3: Switch_Colour(new Color(205f / 255, 103f / 255, 113f / 255)); break; default: Switch_Colour(Color.magenta); break; } } else { Switch_Colour(new Color(Random.Range(0f, 1f), Random.Range(0f, 1f), Random.Range(0f, 1f))); } }
// Update is called once per frame void Update() { if (vehicle_control_holder == null) { vehicle_control_holder = GetComponent <Vehicle_Control_Holder>(); } else { if (Game_State.game_state_inst != null && Game_State.game_state_inst.Get_State() == Game_State.Game_States.in_play) { float hor = vehicle_control_holder.state.ThumbSticks.Right.X; float ver = vehicle_control_holder.state.ThumbSticks.Right.Y; Vector3 input_direction = new Vector3(hor, 0, ver); //get the input direction, this is the direction we want the vehicle to face Vector3 current_rotation = turret_object.transform.rotation.eulerAngles; Vector3 new_rotation = (Quaternion.FromToRotation(turret_object.transform.forward, input_direction) * turret_object.transform.rotation).eulerAngles; //convert input direction to rotation float angle = new_rotation.y - current_rotation.y; //this.transform.RotateAround(turn_point.position, turn_point.up, angle); //removed due weird lepring, behavior reproduced with parent child relationship Quaternion initial = turret_object.transform.rotation; //take initial rotation turret_object.transform.Rotate(0, angle, 0); //rotate by difference between previous angles Quaternion final = turret_object.transform.rotation; //take final rotation turret_object.transform.rotation = Quaternion.Lerp(initial, final, rotate_speed * Time.deltaTime); //lerp between initial and final rotation if (vehicle_control_holder.state.Triggers.Right > 0.5f) { current_turret.Fire(vehicle_control_holder); } else { current_turret.Un_Fire(); } } } }
//refactor so it doesn't require passing vehicle public void Take_Health(int _amount, Vehicle_Control_Holder _firing_vehicle) { health -= _amount; if (health <= 0) { Game_Mode.game_mode_inst.Add_Kill(_firing_vehicle.Get_Player_Index()); print(In_Game_Record.in_game_record_inst.Get_Highest_Kills()[0].kills); Die(); } }
public void Fire(Vehicle_Control_Holder _firing_vehicle) { if (trigger_down == false && Time.fixedTime >= next_fire_time) { GameObject shell_inst = Instantiate(shell, fire_point.transform.position, fire_point.transform.rotation) as GameObject; Shell shell_script = shell_inst.GetComponent <Shell>(); shell_script.Set_Firing_Vehicle(_firing_vehicle); trigger_down = true; next_fire_time = Time.fixedTime + 1.5f; } }
// Use this for initialization void Start() { vehicle_rigidbody = GetComponent <Rigidbody>(); vehicle_control_holder = GetComponent <Vehicle_Control_Holder>(); }
public void Set_Firing_Vehicle(Vehicle_Control_Holder _vehicle) { firing_vehicle = _vehicle; }
// Use this for initialization void Start() { vehicle_control_holder = GetComponent <Vehicle_Control_Holder>(); current_turret = GetComponentInChildren <Turret_Object>(); }