Search Unity

Parallax/Perspective 2.5D Main Menu - Problem

Discussion in 'Scripting' started by ZdzichuRonczka, Oct 31, 2014.

  1. ZdzichuRonczka

    ZdzichuRonczka

    Joined:
    Jan 23, 2014
    Posts:
    8
    Hello. I learning how to make my first game, and what i wanted to to, its use the 2.5d camera system from typical 2D platformer game and make the menu background with several images looking in perspective. I've found some tutorials with this effect, but for me - its still isn't working.

    This is code for parallax:
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class BackgroundParallax: MonoBehaviour {
    5.  
    6.     public Transform[] Backgrounds;
    7.     public float ParallaxScale;
    8.     public float ParallaxReductionFactor;
    9.     public float Smoothing;
    10.  
    11.     private Vector3 _lastPosition;
    12.  
    13.     public void Start () {
    14.         _lastPosition = transform.position;
    15.     }
    16.  
    17.     public void Update ()
    18.     {
    19.         var parallax = (_lastPosition.x - transform.position.x) * ParallaxScale;
    20.  
    21.         for (var i=0; 1 < Backgrounds.Length; i++)
    22.         {
    23.             var backgroundTargetPosition = Backgrounds[i].position.x + parallax * (i * ParallaxReductionFactor + 1);
    24.         Backgrounds[i].position = Vector3.Lerp (
    25.             Backgrounds[i].position,
    26.             new Vector3(backgroundTargetPosition, Backgrounds [i].position.y, Backgrounds [i].position.z),
    27.             Smoothing * Time.deltaTime);
    28.         }
    29.     _lastPosition = transform.position;
    30.     }
    31. }
    32.  
    This one, is going on several gameobjects with textures:
    Code (JavaScript):
    1.      function Update(){
    2.     var hit : RaycastHit;
    3.  
    4.     if(Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition),hit)){
    5.     if(hit.name == "name of gameobject")
    6.     hit.transform.Rotate(Vector3.up * Time.deltaTime);
    7.     }
    8.     }
    Both are from tutorials, but i don't know how to fix this for 2.5d perspective working on main menu, when player is moving his mouse on this menu. Somebody can help fix and make this work? :)

    Some Screenshots [these menus are temporary :) ]:
    mainmenu2d1.jpg mainmenu2d2.jpg
     
    Last edited: Oct 31, 2014