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 Molthor · Apr 15, 2020 at 03:59 PM · prefabspriteglitch

Prefab sprite glitch,Prefab canvas glitch

Hi there, so i am making a mobile game (TowerBlox) style, but with hamburgers. And im having this weird glitch, so i have a spawn point on top of the screen that spawns a prebaf with random sprites(meat, cheese, tomatoes, bacon etc..) and for some reason when they hit the next prefab to stack some of the sprites get behind the previews sprite. but only fails in some combinations, for example if a egg sprite drops on top of a meat sprite it is all good, but the opposite it glitches. Check the screenshot to see whats going on https://ibb.co/txy9wzX marked with a red arrow the ones that glitch. I thought it could have something to do with the layer but the prefab spawns always on the same layer since it is only 1 prefab with randomized sprite.

Am i missing something in the inspector or is it something i can fix with code?

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 Molthor · Apr 22, 2020 at 03:56 PM

Ok so i found out what i need, so when ever a new cloned prefab spawn i need to increment the layer position. so it wont appear in the back of the preview cloned prefab sprite. Gonna give it a try and will post code after if it either way works or not.

Comment
Add comment · Show 1 · 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 Molthor · Apr 22, 2020 at 05:12 PM 0
Share

new update: didn't found a way,. here is the boxscript:

public class BoxScript : $$anonymous$$onoBehaviour { // a forma como spawna a andar para os lados private float $$anonymous$$_x = -2.2f, max_x = 2.2f;

 private bool can$$anonymous$$ove;
 private float move_speed = 3f; // velocidade com que move

 private Rigidbody2D myBody;

 private bool gameOver;
 private bool ignoreCollision;
 private bool ignoreTriggering;

 // teste random sprite
 private int rand;
 public Sprite[] Sprite_Pic;

 //

 public int contadorDeLayer = 2;


 private void Awake()
 {
     myBody = GetComponent<Rigidbody2D>();
     myBody.gravityScale = 0f;
 }

 private void Start()
 {
     rand = Random.Range(0, Sprite_Pic.Length);
     GetComponent<SpriteRenderer>().sprite = Sprite_Pic[rand]; // spawn with a random sprite of pre selected sprites
     // renderer.sortingOrder = (contadorDeLayer + 1); here is where im trying to fix the order as it spawns.


     can$$anonymous$$ove = true;
     
     //radomizar movimento direito ou esquerdo
     
     if(Random.Range(0, 2) > 0)
     {
         move_speed *= -1f; //randomisa o movimento
     }
     GameplayController.instance.currentBox = this;
     contadorDeLayer++;
 }

 private void Update()
 {
     $$anonymous$$oveBox();
 }

 void $$anonymous$$oveBox()
 {
     if (can$$anonymous$$ove)
     {
         Vector3 temp = transform.position;
         temp.x += move_speed * Time.deltaTime;

         if(temp.x > max_x)
         {
             move_speed += -1f; // muda direçao
         }
         else if (temp.x < $$anonymous$$_x)
         {
             move_speed *= -1f;
         }

         transform.position = temp;
     }
 }

 public void DropBox(){
     can$$anonymous$$ove = false;
     myBody.gravityScale = Random.Range(2, 4);
 }
 void Landed()
 {
     if (gameOver) 
         {       
         return;
         } 

         ignoreCollision = true;
         ignoreTriggering = true;

         GameplayController.instance.SpawnNewBox();
         GameplayController.instance.$$anonymous$$oveCamera();
            

 }
 void RestartGame()
 {
     GameplayController.instance.RestartGame();

 }



 void OnCollisionEnter2D(Collision2D target)
 {
     if (ignoreCollision) 
         { 
         return;
         }
     if (target.gameObject.tag == "Platform")
     {
         Invoke("Landed", 2f);
         ignoreCollision = true;
     }
     if (target.gameObject.tag == "Box")
     {
         Invoke("Landed", 2f);
         ignoreCollision = true;
     }
 }

 void OnTriggerEnter2D(Collider2D target)
 {
     if (ignoreTriggering) 
         { 
         return;
         }

     if(target.tag == "GameOver")
     {
         CancelInvoke("Landed");
         gameOver = true;
         ignoreTriggering = true;

         Invoke("RestartGame", 2f);
     }
     
 }

}

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

263 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Instantiate prefab with its component c# 0 Answers

How to change sliced sprites in unity ? 0 Answers

Collider Glitch Makes Player Die 0 Answers

Is it possible to make multiple prefabs out of a single prefab for use in the map editor? 0 Answers

Problem with exe - Sprites don't display correctly 1 Answer


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