Hi everyone,
im wondering how to make an axis work like a button im using a guitar hero controller and have set the 6 main button as a,b,c,d,e,f, and they work fine i set up the yaxis as a button and that works but they dont work together
“strum up” returns true on its own but if im holding another button down it stays false
how ever if i hold strum up true and press A or B then it does play the sounds
its like its backwards
many thanks in advance
using UnityEngine;
using System.Collections;
[RequireComponent(typeof(AudioSource))]
public class GuitarSetup : MonoBehaviour {
public AudioClip Cdown;
public AudioClip Cup;
public AudioClip Emdown;
public AudioClip Emup;
public AudioClip Gdown;
public AudioClip Gup;
public AudioClip Ddown;
public AudioClip Dup;
public AudioSource source;
public bool a;
public bool b;
public bool c;
public bool d;
public bool e;
public bool f;
public bool strumup = false;
void Awake (){
source = GetComponent<AudioSource>();
}
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
//if(Input.GetButtonDown("strum down")){
if( Input.GetAxisRaw("strum up") != 0)
{
if(strumup == false)
{
//noteonedown();
strumup = true;
noteonedown();
}
}
if( Input.GetAxisRaw("strum up") == 0)
{
strumup = false;
}
//noteonedown();
if(Input.GetButtonDown("joy 0")){
a = true;
}
if(Input.GetButtonDown("joy 1")){
b = true;
}
if(Input.GetButtonDown("joy 2")){
c = true;
}
if(Input.GetButtonDown("joy 3")){
d = true;
}
if(Input.GetButtonDown("joy 4")){
e = true;
}
if(Input.GetButtonDown("joy 5")){
f = true;
}
if(Input.GetButtonUp("joy 0")){
a = false;
}
if(Input.GetButtonUp("joy 1")){
b = false;
}
if(Input.GetButtonUp("joy 2")){
c = false;
}
if(Input.GetButtonUp("joy 3")){
d = false;
}
if(Input.GetButtonUp("joy 4")){
e = false;
}
if(Input.GetButtonUp("joy 5")){
f = false;
}
}
void noteonedown(){
if(a == true)
{
CChord();
}
else
{
notetwodown();
}
}
void notetwodown(){
if(b == true)
{
EmChord();
}
else
{
notethreedown();
}
}
void notethreedown(){
if(c == true)
{
GChorddown();
}
else
{
notefourdown();
}
}
void notefourdown(){
if(d == true)
{
DChord();
}
else
{
notefivedown();
}
}
void notefivedown(){
if(e == true)
{
GChordUp();
}
else
{
notesixdown();
}
}
void notesixdown(){
if(f == true)
{
source.clip = Cup;
source.Play();
}
else
{
print("open strum");
}
}
public void CChord () {
source.PlayOneShot(Cdown);
}
public void CChordUp () {
source.PlayOneShot(Cup);
}
public void EmChord () {
source.PlayOneShot(Emdown);
}
public void EmChordup () {
source.PlayOneShot(Emup);
}
public void GChorddown () {
source.PlayOneShot(Gdown);
}
public void GChordUp () {
source.PlayOneShot(Gup);
}
public void DChord () {
source.PlayOneShot(Ddown);
}
public void DChordup () {
source.PlayOneShot(Dup);
}
}