Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by $$anonymous$$ · May 15, 2016 at 08:58 PM · 2d gameunity5background

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

Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image $$anonymous$$ · May 16, 2016 at 06:58 PM 0
Share

No comments... please help

avatar image Jessespike $$anonymous$$ · May 16, 2016 at 07:18 PM 0
Share

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.

avatar image $$anonymous$$ · May 16, 2016 at 09:30 PM -2
Share

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??

1 Reply

· Add your reply
  • Sort: 
avatar image
0

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));

Material.SetTextureOffset

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;
Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image $$anonymous$$ · May 16, 2016 at 07:41 PM 0
Share

Thanks but not work in z-axis

avatar image Jessespike $$anonymous$$ · May 16, 2016 at 07:53 PM 0
Share

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;
avatar image $$anonymous$$ Jessespike · May 16, 2016 at 08:10 PM 0
Share

Thanks .not move

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

2 People are following this question.

avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges