What we learned from the Unity free plugin (1): Ship remote control by Fast Buoyancy

Plug-in name: Fast Buoyancy
official website address: https://assetstore.unity.com/packages/tools/physics/fast-buoyancy-61079

The first is the ship control. In Update, "can't go back before stopping when moving forward" (and vice versa)

if (Input.GetKey(KeyCode.Q))
      ship.RudderLeft();
    if (Input.GetKey(KeyCode.D))
      ship.RudderRight();

    if (forward)
    {
    
    
      if (Input.GetKey(KeyCode.Z))
        ship.ThrottleUp();
      else if (Input.GetKey(KeyCode.S))
      {
    
    
        ship.ThrottleDown();
        ship.Brake();
      }
    }
    else
    {
    
    
      if (Input.GetKey(KeyCode.S))
        ship.ThrottleUp();
      else if (Input.GetKey(KeyCode.Z))
      {
    
    
        ship.ThrottleDown();
        ship.Brake();
      }
    }

    if (!Input.GetKey(KeyCode.Z) && !Input.GetKey(KeyCode.S))
      ship.ThrottleDown();

    if (ship.engine_rpm == 0 && Input.GetKeyDown(KeyCode.S) && forward)
    {
    
    
      forward = false;
      ship.Reverse();
    }
    else if (ship.engine_rpm == 0 && Input.GetKeyDown(KeyCode.Z) && !forward)
    {
    
    
      forward = true;
      ship.Reverse();
    }
  }

The ship here refers to another script PropellerBoats.cs. Both scripts are placed on the gameobject of the ship.

Guess you like

Origin blog.csdn.net/MikeW138/article/details/89551141