i was useing the number buttons to switch from block to block but i have now ran out of numbers and i was wanting to use the mouse wheel to switch from block to block?
Hi again,
So you need to detect the mouse scroll wheel input like this: Input.GetAxis(“Mouse ScrollWheel”) - It returns the delta movement that happened in the last frame which could be a positive/negative value according to the direction of scroll. Decide or expose a minimum delta value (cap) so you know when to go to the next block.
Then give an Id to your blocks, so when value is positive (and larger than your minimum delta cap) you go to the next block and vice versa.
could you maybe give me a basic script of how to set it up because i can not work out how to do it
A simple script which lets you select items using the mouse scroll wheel. When you reach first item, it goes back to last and vice versa.
Download file from here: https://dl.dropbox.com/u/9385978/SharedScripts/ScrollWheelControls.cs
(*Change maxBlocks according to your needs)
For reference the code is as follows:
using UnityEngine;
using System.Collections;
public class ScrollWheelControls : MonoBehaviour {
int currentBlock =0;
int maxBlocks = 5;
void Update () {
float scrollValue = Input.GetAxis("Mouse ScrollWheel");
if (scrollValue < 0)
{
if (currentBlock > 0)
{
currentBlock--;
}
else
{
currentBlock = maxBlocks;
}
SelectBlock(currentBlock);
}
else if (scrollValue > 0)
{
if (currentBlock < maxBlocks)
{
currentBlock++;
}
else
{
currentBlock =0;
}
SelectBlock(currentBlock);
}
}
void SelectBlock(int CurrentBlock)
{
print("Selected block is : "+ CurrentBlock);
}
}