- Home /
I need the sound of clothes to play when the camera rotates.
float amount = 0.055f;
public float maxAmount = 0.09f;
float smooth = 3;
Vector3 def;
Vector2 defAth;
Vector3 euler;
GameObject ath;
AudioSource audioArmsMove;
void Start()
{
def = transform.localPosition;
euler = transform.localEulerAngles;
audioArmsMove = gameObject.GetComponent<AudioSource>();
}
float _smooth;
// Update is called once per frame
void Update()
{
_smooth = smooth;
float factorX = -Input.GetAxis("Mouse X") * amount;
float factorY = -Input.GetAxis("Mouse Y") * amount;
if (factorX > maxAmount)
factorX = maxAmount;
if (factorX < -maxAmount)
factorX = -maxAmount;
if(factorY > maxAmount)
factorY = maxAmount;
if (factorY < -maxAmount)
factorY = -maxAmount;
Vector3 final = new Vector3(def.x + factorX, def.y + factorY, def.z);
transform.localPosition = Vector3.Lerp(transform.localPosition, final, Time.deltaTime * _smooth);
}
Answer by aoun111 · Jul 08, 2019 at 08:59 AM
In the Update method, create an if statement checking for input.getaxis on mouse x OR mouse y, if its true, play the cloth sound, else return.
It's really not that difficult, Unity actually tells you what to do after you type in Input.GetAxis(
Give it a go and see if you can do it. You'll never get better if people do it all for you.
As @ak0rn says, do try to solve it yourself. It helps you understand some syntax for future similar problems... :D
If you really need this:
//In Update function
if (Input.GetAxis("$$anonymous$$ouse X") || Input.GetAxis("$$anonymous$$ouse Y"))
{
//Play sound
}
Answer by Ak0rn · Jul 08, 2019 at 09:18 AM
Not sure if it would work as I've never tried but you could have a Vector3 of currentCamPos inside of update which will constantly look at the cameras current position and a lateupdate Vector3 of prevCamPos then a vector3 distance inside of update to check if the two don't match and if they don't then you play sound.
No clue if it'll work but worth a try.
After thinking about it, although this would be fun to write it's clunky.
But why not get axis on mouse X and Y, and if its true, play a sound?
because where's the fun in that? Who needs speed.
Joking aside, use getAxis.