- Home /
Scrolling GameObject in Unity3D
Most problems with computer programming I can solve alone, but sometimes it's hard to find a solution. And now I have such a problem.
Is there a possibility to write a script for game object scrolling? Just like textures. In other words, using objects like textures: scroll them and make a menu (when clicking, something happen). For example, we have seven 3D boxes (for every day of week) and we can scroll choosing one and the rest is faded at the same time. The chosen one can be highlighted in some way ( becomes bigger or lightened).
Scrolling 3D objects is not hard, but I'm having trouble visualizing how it is scrolling and it relationship to other objects. This line in particular is confusing to me:
For example, we have seven 3D boxes (for every day of week) and we can scroll choosing one and the rest is faded at the same time.
What does 'scroll choosing one' mean, and what happens to the other days of the week when it is scrolling?
There are seven boxes like a calendar (for a week). it's like a shelf. Every day of week can have its box so that we can put something in. if we choose one day, for example $$anonymous$$onday, the box for $$anonymous$$onday should be somehow highlighted, the rest days (boxes) should be faded. We can scroll horizontally the days using arrows and choose days.
The user can choose $$anonymous$$onday:
| $$anonymous$$onday| Tuesday | ... | Saturday | Sunday |
<------------------------------------------->
Scrolling
$$anonymous$$onday highlighted, all other days faded
Or Saturday:
| $$anonymous$$onday| Tuesday | ... | Saturday | Sunday |
<------------------------------------------->
Scrolling
Saturday highlighted, all other days faded
The user can choose days he/she wants. And the chosen day is highlighted and other days faded. That is game objects (boxes) faded.
This is a complicated task and hard to explain. Could you imagine seven boxes to choose for the users? And he/she can choose one at one time. And the box chosen by him/her is highlighted, all other faded. Then, he/she can choose other box: the previous chosen box will be faded and the chosen highlighted. Only one box is always highlighted, the rest of them faded.
This question is not a good fit for Unity Answers. Unity Answers deals with single, specific technical problems. Your question has many separate technical issues, most of which have been covered a few times in the past. Break your question apart, experiment, and when you get stuck, post back with a specific questions. Here are some of the issues/tasks in your question:
Select either Raycasting/Touch or On$$anonymous$$ouseDown() to handle input
Drag and drop code...multiple different versions have been posted on Unity Answers and Unity Forums.
Velocity and friction. $$anonymous$$ost people with this kind of interface expects to be able to swipe and have the list continue to scroll for a bit.
Stops at the ends. Could be a simple clamp, but often people want it to bounce at the ends.
Figure out Text/Label display (several choices listed below)
Figure out selection method
Given that most solutions involve colliders for individual labels, you have to figure out how to propagate swipe movements from the children.
Figure out interface to export the selection.
Display methods
Using separate game objects with separate textures - simple but will result in 7, non-batched draw calls.
Use a single quad with seven (or possibly eight if there is a no-day selected state) textures representing each of the selection states.
Use seven quads and a sprite sheet for displaying the days. The sprite sheet would contain 14 'images'...a selected and un-selected state for each day of the week. The UVs in the mesh would be set to map in the correct 'image' from the sprite sheet. This is how commerical products like NGUI and EZGUI do it.
Build a single mesh with seven quads...one for each day of the week. A more complicated solution, but it has the highest efficiency and would simplify the drag code a bit.
robertbu, you yourself complicated the problem. $$anonymous$$y question was: is it possible to scroll game objects? And maybe simple example. I know raycasting On$$anonymous$$ouseDown(), DragNDrop code, and many things you wrote. I have never seen such an example, even a simple one, so I'm asking. Why did you close my question? If you don't know or don't want to help, just do nothing.
@$$anonymous$$aza - If you already know Drag and Drop, then to scroll basic scroll is just confining the drag to one axis. And yes there have been questions and answers about dragging confined to a single axis.
If you don't know or don't want to help, just do nothing.
I may not always get it right, but there are standards on this site that I'm increasingly trying to abide by. And I still think I got it right this time. Here is the core of your question quoted from you:
in other words, using objects like textures: scroll them and make a menu (when clicking, something happen).
This is not a single specific question, and you brought nothing to the table with respect to your own code, or how you were attempting the design. And I have implemented this functionality a couple of times, so I have a pretty good idea of some ways it can be done (and the pitfalls). What I was asking you to do is spend some time researching the various technical issues within your question and then ask single, specific questions.
Answer by Tomza · Jan 14, 2015 at 06:58 PM
The code for object scrolling.
using UnityEngine;
using System.Collections;
public class ScrollNewProductsStatic : MonoBehaviour {
public static int curWeapon;
private int currentWeapon;
public Transform[] weapons;
// Use this for initialization
void Start () {
curWeapon = 0;
}
// Update is called once per frame
void Update () {
if(curWeapon == weapons.Length + 1){
curWeapon = 0;
}
if(curWeapon == -1){
curWeapon = 5;
}
changeWeapon(curWeapon);
//Debug.Log("Static :" + curWeapon);
}
public void changeWeapon(int num) {
currentWeapon = num;
for(int i = 0; i < weapons.Length; i++) {
if(i == num){
weapons[i].gameObject.transform.localScale = new Vector3(2.0f,2.0f,2.0f);
}
else{
weapons[i].gameObject.transform.localScale = new Vector3(1.0f,1.0f,1.0f);
}
}
}
}
This script is for all 3D objects to be scrolled. I can be attached to the top of the Projector object hierarchy (name of the projector). Then you need to two other scripts for two arrows to scroll the objects.
The first arrow:
using UnityEngine;
using System.Collections;
public class ScrollNewProductsLeft : MonoBehaviour {
private int getScroll;
private int newScrollM;
// Use this for initialization
void Start () {
newScrollM = 0;
}
// Update is called once per frame
void Update () {
}
void OnMouseDown(){
ScrollNewProductsStatic.curWeapon++;
}
}
The second arrow:
using UnityEngine;
using System.Collections;
public class ScrollNewProductsRight : MonoBehaviour {
private int getScroll;
private int newScrollA;
// Use this for initialization
void Start () {
newScrollA = 0;
}
// Update is called once per frame
void Update () {
}
void OnMouseDown(){
ScrollNewProductsStatic.curWeapon--;
}
}
Apply one script to the first arrow and the other to the second.
Feel free to improve the scripts because I have no time. It's only an idea how to do that.
In this example, scrolling is just making the current object bigger, but you can use other effects.
Have a fun :)!
Your answer
Follow this Question
Related Questions
individual object menu 0 Answers
UI Questions 1 Answer
Cube click pop-up menu 0 Answers
Updating Prefabs within other Prefabs (Nested) 1 Answer
button wont work in GUI.BeginScrollView 0 Answers