What im trying to do is when im dragging an object if i roll the scrollwheel up i want the object to go farther away and when i roll the scroll wheel down i want the object to come closer while im still dragging it. Here is my script:
function OnMouseDown () {
var screenPos = Camera.main.WorldToScreenPoint(transform.position);
var offset = transform.position - Camera.main.ScreenToWorldPoint(Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPos.z));
while (Input.GetMouseButton(0))
{
var curScreenPos = Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPos.z);
var curPos = Camera.main.ScreenToWorldPoint(curScreenPos) + offset;
transform.position = curPos;
yield;
if(Input.GetAxis("Mouse Scrollwheel"))
{
WHAT DO I PUT HERE
transform.position= ????
}
}
}
Can you tell me what i would put there to be able to read the mouse wheel up and down movements?
use the Input.GetAxis(“Mouse ScrollWheel”) so transform.position.z or whatever += Input.GetAxis(“Mouse ScrollWheel”)
the value is very small so you may want to multiply it by 10 or 100 or something
i tried this but it didnt work
transform.position.z = Input.GetAxis("Mouse ScrollWheel") *10;
is that what you meant?
need += not = or it will not work
I tried putting that same code into the script with += and it still does not work.
I have :
function OnMouseDown () {
var screenPos = Camera.main.WorldToScreenPoint(transform.position);
var offset = transform.position - Camera.main.ScreenToWorldPoint(Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPos.z));
while (Input.GetMouseButton(0))
{
var curScreenPos = Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPos.z);
var curPos = Camera.main.ScreenToWorldPoint(curScreenPos) + offset;
transform.position = curPos;
yield;
if(Input.GetAxis("Mouse Scrollwheel"))
{
transform.position.z += Input.GetAxis("Mouse ScrollWheel") * 10 ;
}
}
}
is that right?
Ok here’s an idea.
- Check for the mouse button being down.
- If so, shoot a ran from cam coords to world coords.
- If it intersects an object, you know you have something draggable. Perhaps change the color of the said object to signify this.
- While the button is still down, check for scrolling of the mousewheel.
- If the user scrolls, move the object accordingly along its forward and backwards axis.
And no, simply adding the axis of the scrollwheel to the position of z is not right.
But 1 minute, I will post up a code snippet example if someone doesn’t beat me to it. ; )
All the buttons are working and i have the dragging working i just need the scrollwheel to bring the object closer or further away. Im not sure what to put in the Mouse Scrollwheel if statement.
Ok I was gonna do a full thing but in that case this will work. 
using UnityEngine;
using System.Collections;
public class drag : MonoBehaviour {
public Transform obj;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (Input.GetMouseButton(0) Input.GetAxis("Mouse ScrollWheel") != 0)
{
obj.position += new Vector3(0, 0, 5 * Input.GetAxis("Mouse ScrollWheel"));
}
}
}
Whenever the mouse button is down and the scrollwheel is moving, move the object along the forward vector based on the scrollwheel current axis.
This is not working for me it detects the scrollwheel but the object doesnt move.
Here is my code:
if (Input.GetAxis("Mouse ScrollWheel"))
{
transform.position += new Vector3(0, 0, 5 * Input.GetAxis("Mouse ScrollWheel"));
Debug.Log("SCROLLED!");
}
Works for me…O_o
Did you but the object into the slot? 
this is from the dragging script attached to the object.