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 /
avatar image
0
Question by benbendixon · Sep 03, 2015 at 05:06 AM · bugscalingverticaldownscroller

Clones are being downscaled for no reason?

So I am making a vertical scroller, and after just finishing up my script that will keep creating my background I am getting an odd error, or rather bug. It might just be in my code, but I can't figure it out and I need a second (or a dozen) extra pairs of eyes. To start things off here is my code:

 using UnityEngine;
 using System.Collections;
 
 [RequireComponent (typeof(SpriteRenderer))] // Makes sure there is a sprite as part of the gameObject
 
 public class Tiling : MonoBehaviour {
     
     public int offsety = 2; // The offset so no wierd errors
     public bool hasBuddy = false; // Checks if we need to instantiate / spawn stuff
     public bool reverseScale = false; // Used if object isn't tilable
     private float spriteHeight = 0f; // The height of the element
     private Camera cam;
     private Transform myTransform;
     
     void Awake ()
     {
         cam = Camera.main;
         myTransform = transform;
     }
     
 
     void Start () {
         SpriteRenderer sRenderer = GetComponent<SpriteRenderer>();
         spriteHeight = sRenderer.sprite.bounds.size.y;
     }
     
     // Update is called once per frame
     void Update () 
     {
         // Calculate where the camera can see
         float camVerticalExtend = cam.orthographicSize * Screen.width/Screen.height;
         
         // Calculate the y pos where the camera can see the edge of the sprite
         float edgeVisiblePositionBottom = (myTransform.position.y - spriteHeight/2) + camVerticalExtend;
         
         // Check if we need a new sprite
         if (cam.transform.position.y <= edgeVisiblePositionBottom + offsety && hasBuddy == false)
         {
             MakeNewBuddy(-1);
             hasBuddy = true;
         }    
         else if (cam.transform.position.y >= edgeVisiblePositionBottom + offsety)
         {
             hasBuddy = false;
         }
     }    
 
     
     // How we spawn new sprites!!!
     void MakeNewBuddy (int buddyValue)
     {
         // Where should the new sprite go? (this is how we calculate it)
         Vector3 newPosition = new Vector3 (myTransform.position.x, myTransform.position.y + spriteHeight * buddyValue, myTransform.position.z);
         Transform newBuddy = Instantiate (myTransform, newPosition, myTransform.rotation) as Transform;
         
         // if its not tileable, then lets reverse the x, y, and z. (just makes it look nice)
         if (reverseScale == true)
         {
             newBuddy.localScale = new Vector3 (newBuddy.localScale.x*-1, newBuddy.localScale.y*-1, newBuddy.localScale.z*-1);
         }
     
         // Makes sure there arent a ton of different layer values for each new sprite created.
         newBuddy.parent = myTransform.parent;
         
         // It now has a sprite buddy! So lets not spawn a bunch more until we need one.
         if (buddyValue < 0){
             newBuddy.GetComponent<Tiling>().hasBuddy = true;
         }
     }    
 }
 
 

The sprites are getting downscaled by what appears to be different amounts when they are cloned. The scaling on my background clouds is turned down to roughlly .84, and my buildings to the side of the cloud is scaled down to a scaling of .76. Here is a screenshot of what is occuring.

alt text

Anyway after finally getting my scrolling to work I was saddened by this bug :( maybe you can make me happy! All replies are welcome!

Thanks a bunch!

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by hulahoolgames · Sep 03, 2015 at 07:02 AM

Check if the scale gets screwed up after this line

 newBuddy.parent = myTransform.parent;

Put some debug statements before and after this line to see if scale changes. Also, if reverseScale is ever true check if that affects it in anyway. Hope this helps in some way!

Comment
Add comment · Show 4 · 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 benbendixon · Sep 03, 2015 at 01:29 PM 0
Share

Thanks for the advice, that was indeed the problematic line. The scaling is now 1 for all of the clones. However, The first clone that is made is still smaller than the original (the scaling is still 1 however). Every clone after that matches up to the one that was made. Here is a screen shot (NOTE: ignore the bar in the middle, it follows the player and has a script attatched to it. It is irrelevant.) alt text

avatar image Suddoha · Sep 03, 2015 at 01:45 PM 1
Share

@benbendixon What's the scale of "myTransform.parent", "myTransform" and what's the parent of the first object that has got the correct size?

The instantiated objects may have a scale of 1, but that is always relative to the parents scale. If your parent has a scale of 0.5 for example, that'll squeeze your childs in the respective axis.

avatar image benbendixon · Sep 03, 2015 at 02:30 PM 0
Share

@Suddoha You sir are a genius, my parents were just random empty objects because I wanted to be organized, and their scaling was odd. $$anonymous$$uch love. $$anonymous$$uch love.

avatar image hulahoolgames · Sep 03, 2015 at 03:18 PM 0
Share

Yes! As @Suddoha rightly mentioned, the parent affects child's transform, the same reason I suspected the problem to be in the line where you change the clones parent. Glad it helped :)

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

When I Re-Spawn in my game, I can't look up or down. How can fix this? 0 Answers

GUI begin vertical, to go Up 1 Answer

rigidbody2D.velocity.y not recording C# 1 Answer

Random Gameobject Scaling 0 Answers

Animator bug when activating a transition condition using SetBool 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