Quantcast
Channel: Questions in topic: "error message"
Viewing all articles
Browse latest Browse all 2891

Simple error but I'm just a begginer and cant figure this out, due to outdated API.

$
0
0
Hello helper, and thanks for helping me, so my problem is my playing sound effects for fire sound, are too low for enemies and players, when i run the game and i try to shoot using my left click mouse the fire sound is really low and i'm trying to control its volume by a script, same for the enemies fire sound so here is my code below, and error message i get. Error Message : error CS0120: An object reference is required to access non-static member `UnityEngine.AudioSource.volume' using UnityEngine; using System.Collections; public class PlayerController : MonoBehaviour { //A variable(box in inspector where you can adjust the speed of the moving character(Player)) public float speed = 5.0f; public float padding = 1; public GameObject bulletShot; private float xmax = 78; private float xmin = -79; public float projectileSpeed = 10; public float projectileRepeatRate = 0.2f; public float health = 350; public AudioClip fireSound; void Start() { Camera camera = Camera.main; float distance = transform.position.z - camera.transform.position.z; xmin = camera.ViewportToWorldPoint(new Vector3(0,0,distance)).x + padding; xmax = camera.ViewportToWorldPoint(new Vector3(1,1,distance)).x + padding; } void Fire() { Vector3 offSet = new Vector3 (-2,0.40f,0); GameObject beam = (GameObject)Instantiate(bulletShot, transform.position + offSet, Quaternion.identity); beam.GetComponent().velocity = new Vector3 (-projectileSpeed,0,0); fireSound = AudioSource.volume(2,3); AudioSource.PlayClipAtPoint(fireSound, transform.position); } // Update is called once per frame void Update () { if (Input.GetMouseButtonDown(0)) { InvokeRepeating("Fire", 0.0001f, projectileRepeatRate); } if (Input.GetMouseButtonUp(0)) { CancelInvoke("Fire"); } //Allowing the player to move in the X-axis if (Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.LeftArrow)) { transform.position = new Vector3 ( Mathf.Clamp(transform.position.x - speed * Time.deltaTime, xmin,xmax), transform.position.y, transform.position.z ); } if (Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.RightArrow)) { // Rotate the object around its local X axis at 1 degree per second transform.position = new Vector3 ( Mathf.Clamp(transform.position.x + speed* Time.deltaTime, xmin, xmax), transform.position.y, transform.position.z ); } } void OnTriggerEnter2D (Collider2D collider){ Projectile missile = collider.gameObject.GetComponent(); if (missile) { health -= missile.GetDamage(); missile.Hit(); if (health <= 0 ) { Destroy(gameObject); } } } }

Viewing all articles
Browse latest Browse all 2891

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>