Hello Guys!
Im Newbie in Unity3d so can anybody asking how to change Volume of AudioClip?
Heres The code
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class FPSController : MonoBehaviour
{
public float speed = 10f;
public float RunSpeed=40f;
public float sensitivity = 2f;
CharacterController player;
public AudioClip[] music;
private AudioSource soundComponent;
public float Volume = 0.2f;
public GameObject eyes;
float moveFB;
float moveLR;
float rotX;
float rotY;
public float vertVelocity;
public float jump = 30f;
float jumpTimes;
float shift;
void Awake()
{
soundComponent= GetComponent<AudioSource>();
soundComponent.clip = music[0];
soundComponent.volume = 0.2f;
soundComponent.Play();
}
// Use this for initialization
void Start()
{
soundComponent = (AudioSource)gameObject.AddComponent<AudioSource>();
player = GetComponent<CharacterController>();
}
//************************************************************ */
// Update is called once per frame
void Update()
{
Volume =0.2f;
Physics.gravity = new Vector3(0, -70.0F, 0);
moveFB = Input.GetAxis("Vertical") * speed;
moveLR = Input.GetAxis("Horizontal") * speed;
rotX = Input.GetAxis("Mouse X") * sensitivity;
rotY -= Input.GetAxis("Mouse Y") * sensitivity;
rotY = Mathf.Clamp(rotY, -60f, 60f);
Vector3 movement = new Vector3(moveLR, vertVelocity, moveFB);
transform.Rotate(0, rotX, 0);
eyes.transform.localRotation = Quaternion.Euler(rotY, 0, 0);
movement = transform.rotation * movement;
player.Move(movement * Time.deltaTime);
if(Input.GetKey(KeyCode.LeftShift))
{
speed=RunSpeed;
}
else{
speed=26f;
}
if (player.isGrounded == true)
{
jumpTimes = 0;
}
if (jumpTimes < 1)
{
if (Input.GetButtonDown("Jump"))
{
vertVelocity += jump;
jumpTimes += 1;
}
}
}
void FixedUpdate()
{
if (player.isGrounded == false)
{
vertVelocity += Physics.gravity.y * Time.deltaTime;
}
else
{
vertVelocity = 0f;
}
}
void OnTriggerEnter( Collider other )
{
if (other.gameObject.tag == "House")
{
Volume=Volume/2;
}
}
void OnTriggerExit( Collider other )
{
if (other.gameObject.tag == "House")
{
soundComponent.volume=Volume*2;
}
}
}