3D Scrolling in 2D game
How do I move ground such as the video ? I want to move background in the z-axis . https://www.youtube.com/watch?v=k4l2C6Ka2H8 c# script please Thanks
Do not add answers that do not answer the question. Reply with a comment if you have something to add, or bump in this case.
move ground , tree , other object in the z-axis.such as the video https://www.youtube.com/watch?v=k4l2C6$$anonymous$$a2H8 Thanks with this code scroll in horizontal using UnityEngine; using System.Collections;
public class ScrollH : $$anonymous$$onoBehaviour {
public float speed = 0.5f;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
Vector2 offset = new Vector2 (0, Time.time * speed);
GetComponent<Renderer> ().material.mainTextureOffset = offset;
}
}
how to use this code for z-axis??
Answer by Jessespike · May 16, 2016 at 07:27 PM
It's not 3D. It's actually a simple scrolling texture.
Material material = GetComponent<Renderer>().material;
material.SetTextureOffset("_MainTex", new Vector2(0f, material.GetTextureOffset("_MainTex").y + Time.deltaTime));
As for the rock getting larger as it gets closer, it's a 2D trick as well. Set the scale of the rock as it moves away from the horizon (center of screen)...
float maxScale = 2.5f; // scale of object when it is closest
Vector3 screenPos = Camera.main.WorldToScreenPoint(transform.localPosition);
float objectScale = (1 - (screenPos.y / (Screen.height / 2))) * maxScale;
transform.localScale = Vector3.one * objectScale;
2D does not need a z-axis. This is pseudo 3D: A 2D effect simulating 3D. If you want to use 3 axises then, there's no point in doing it in 2D. $$anonymous$$ight as well do it in 3D...
$$anonymous$$akes no sense to me, but if you wanted to control the object's scale with the z-axis then do it, it's silly though:
transform.localScale = Vector3.one * transform.localPosition.z;
Your answer
Follow this Question
Related Questions
How do I turn off the previous object? 1 Answer
Everything is appearing behind camera background 0 Answers
creating background (infinite) for 2d unity game. 1 Answer
How could I do pixel art with no blurring rotation like in Tiny Survivor? 0 Answers
2D Android Game Rapid Jumping Problem,Unity 2018.2.9f1 Android 2d Speed Jumping 0 Answers