- Home /
Question by
yohanrw · Oct 20, 2013 at 01:51 PM ·
rigidbodymousewheel
Listening to the "Mouse Scroll Wheel"
Hello,
I need to listen to the mouse scroll view, and if the user scrolled up, increase the "Fire Power". Following is my code.
using UnityEngine;
using System.Collections;
public class Shooter : MonoBehaviour {
public Rigidbody bullet;
public float power = 1500f;
public float moveSpeed = 25f;
// Update is called once per frame
void Update ()
{
float h = Input.GetAxis("Horizontal") * Time.deltaTime * moveSpeed;
float v = Input.GetAxis("Vertical") * Time.deltaTime * moveSpeed;
transform.Translate(h,v,0);
if(Input.GetButtonUp("Fire1"))
{
Rigidbody instance = Instantiate(bullet,transform.position,transform.rotation) as Rigidbody;
Vector3 fwd = transform.TransformDirection(Vector3.forward);
instance.AddForce(fwd*power);
}
else if(Input.GetButtonUp("Mouse ScrollWheel"))
{
power = power * 2;
}
}
}
But, this "MouseScrollWheel" part seems not working. What am I doing wrong?
Please help.
Comment
Answer by meat5000 · Oct 20, 2013 at 01:54 PM
http://answers.unity3d.com/questions/13485/implementing-the-scrollwheel.html
I think it's all here in this post
Input.GetAxis("Mouse ScrollWheel")
in a nutshell
Must use GetAxis