Cara mengatasi warning Unity WebGL yang berbunyi: HTTP Response Header “Content-Type” configured incorrectly on the server for file Build/xxx.wasm , should be “application/wasm”. Startup time performance will suffer.

Kalian bisa menambahkan sebuah file bernama .htaccess di lokasi yang sama dengan file html game Unity yang dibuild oleh Unity, yang isinya adalah kode ini guys:

# This configuration file should be uploaded to the server as "<Application Folder>/Build/.htaccess"
# This configuration has been tested with Unity 2020.1 builds, hosted on Apache/2.4
# NOTE: "mod_mime" Apache module must be enabled for this configuration to work.
<IfModule mod_mime.c>

# The following lines are required for builds without decompression fallback, compressed with gzip
RemoveType .gz
AddEncoding gzip .gz
AddType application/octet-stream .data.gz
AddType application/wasm .wasm.gz
AddType application/javascript .js.gz
AddType application/octet-stream .symbols.json.gz

# The following lines are required for builds without decompression fallback, compressed with Brotli
RemoveType .br
RemoveLanguage .br
AddEncoding br .br
AddType application/octet-stream .data.br
AddType application/wasm .wasm.br
AddType application/javascript .js.br
AddType application/octet-stream .symbols.json.br

# The following line improves loading performance for uncompressed builds
AddType application/wasm .wasm

# Uncomment the following line to improve loading performance for gzip-compressed builds with decompression fallback
# AddEncoding gzip .unityweb

# Uncomment the following line to improve loading performance for brotli-compressed builds with decompression fallback
# AddEncoding br .unityweb

Script car controller sederhana untuk menjalankan mobil di Unity

Di postingan ini ingin saya share sebuah script car controller sederhana untuk menjalankan mobil.

Seperti apa penggunaannya bisa kalian lihat di video di bawahnya ya. Berikut scriptnya (Controller.cs):

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Controller : MonoBehaviour
{
    //Adding audio source 
    //public AudioSource audioSourceIddle;
    //public float minimumPitchIdle = 0.5f;
    //public AudioSource audioSourceAcc;
    //public float minimumPitchAcc = 0.5f;




    //Making reference to wheel colliders
    [SerializeField] WheelCollider FrontRight;
    [SerializeField] WheelCollider FrontLeft;
    [SerializeField] WheelCollider BackRight;
    [SerializeField] WheelCollider BackLeft;

    //Getting Reference to phisycal wheel meshes
    [SerializeField] Transform FrontRightTransform;
    [SerializeField] Transform FrontLeftTransform;
    [SerializeField] Transform BackRightTransform;
    [SerializeField] Transform BackLeftTransform;


    public float acceleration = 30000f;
    public float BreakingForce = 8000f;
    public float MaxTurnAngle = 30f;


    private float CurrentAcceleration = 0f;
    private float CurrentBreakingForce = 0f;
    private float CurrentTurnAngle = 0f;
    private float CurrentAccSound = 0f;

    

    private void FixedUpdate()
    {
        //Making reference to the audio
        //audioSourceIddle = GetComponent<AudioSource>();
        //audioSourceAcc = GetComponent < AudioSource>();
        //audioSource.pitch = minimumPitch;

        //Get forward /backward acceleration from the vertical axis (W and S keys)
        CurrentAcceleration = acceleration * Input.GetAxis("Vertical")*(-1);
        CurrentAccSound = Input.GetAxis("Vertical");
        //setting up sound
        //if (CurrentAccSound < 0.0)
        //{
            //audioSourceIddle.pitch = (float)(minimumPitchIdle-0.1);
        //}
        //else if (CurrentAccSound > 0.7)
        //{
          //  audioSourceAcc.volume = minimumPitchAcc;
        //
        //else
        //{
         //   audioSourceIddle.pitch = minimumPitchIdle;
        //}
        
        

        //give CurrentBreakForce a value if space key is being pressed
        if (Input.GetKey(KeyCode.Space))
            CurrentBreakingForce = BreakingForce;
            //audioSource.pitch = minimumPitch;
        else
            CurrentBreakingForce = 0;
        //Front wheels acceleration
        FrontRight.motorTorque = CurrentAcceleration;
        FrontLeft.motorTorque = CurrentAcceleration;
        BackRight.motorTorque = CurrentAcceleration;
        BackLeft.motorTorque = CurrentAcceleration;
        //Apply braking to the four wheels
        FrontRight.brakeTorque = CurrentBreakingForce;
        FrontLeft.brakeTorque = CurrentBreakingForce;
        BackRight.brakeTorque = CurrentBreakingForce;
        BackLeft.brakeTorque = CurrentBreakingForce;

        //Stearing
        CurrentTurnAngle = MaxTurnAngle * Input.GetAxis("Horizontal");
        FrontRight.steerAngle = CurrentTurnAngle;
        FrontLeft.steerAngle = CurrentTurnAngle;

        //Update position and rotation of wheel meshes
        UpdateWheel(FrontRight, FrontRightTransform);
        UpdateWheel(FrontLeft, FrontLeftTransform);
        UpdateWheel(BackRight, BackRightTransform);
        UpdateWheel(BackLeft, BackLeftTransform);

    }

    void UpdateWheel(WheelCollider col, Transform trans) {
        //Get state of collider
        Vector3 position;
        Quaternion rotation;
        col.GetWorldPose(out position, out rotation);
        //Set wheel to the same state as collider
        trans.position = position;
        trans.rotation = rotation;
    }
}

Ini videonya:

Cara membuat pesawat terbang di Unity dan membuat kontrol pesawat dengan menggunakan tombol WASD di keyboard

Di video tutorial ini saya akan berbagi pengetahuan game development Unity tentang cara membuat pesawat terbang yang bisa kamu kendalikan dengan memencet tombol WASD di keyboard.

Berikut ini script Pesawat.cs yang kamu lihat di video di atas:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Pesawat : MonoBehaviour
{
	
	public float kecepatan = 10f;
	
	Rigidbody rb;
	
    // Start is called before the first frame update
    void Start()
    {
        rb = GetComponent<Rigidbody>();
    }

    // Update is called once per frame
    void Update()
    {
        rb.velocity = transform.forward * kecepatan;
		
		if(Input.GetKey(KeyCode.W)){
			transform.Rotate(.1f,0,0);
		}
		if(Input.GetKey(KeyCode.S)){
			transform.Rotate(-.1f,0,0);
		}
		if(Input.GetKey(KeyCode.A)){
			transform.Rotate(0,0,.6f);
		}
		if(Input.GetKey(KeyCode.D)){
			transform.Rotate(0,0,-.6f);
		}
    }
}

Cara membuat suara mobil mengikuti kecepatannya di Unity

Di tutorial sebelumnya saya sudah membuat mobil pickup yang bisa dikontrol dengan tombol panah di keyboard untuk menjalankannya. Video itu di sini:

Nah kali ini, tiba saatnya saya menambahkan suara mesin pada mobil ini, yang suaranya nanti bakal terdengar sesuai dengan kecepatan mobil. Kalau mobilnya berjalan kencang, pitchnya dinaikkan, kalau pelan diturunkan, seperti itu lah kurang lebihnya.

Kalau kamu mau langsung mengunduh file project yang saya kerjakan di video ini, silahkan buka https://creativeshop.ciihuy.com/product/car-wheel-colliders-with-engine-audio-script/

Tonton video tutorial ini: