Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
1
Question by Detinator10 · Jul 09, 2014 at 03:20 AM · spritespriterenderer

Why can't the camera render the sprite?

I have a game I'm making with Unity2D and I coded an enemy. I had programmed it and I wanted to track it's movement by making it render a sprite. The problem is the sprite doesn't show when you're playing the game. This is a problem because the enemy is invisible. It shows the sprite on the scene view but it is invisible in the game view. I am using the same sprite renderer component (I literally copied and pasted it) of my main character who does show up in the game. What could be wrong with my enemy? This is the code in the script attached to my enemy: using UnityEngine; using System.Collections;

 public class EnemyScript : MonoBehaviour {
     public float maxSpeed = 1f;
     bool facingRight = true;
     public LayerMask whatIsGround;
     float groundRadius = 0.2f;
     public Transform GroundCheck;
     public bool grounded = false;
     public bool Dead = false;
     public GameObject player;
     float originalmove;
     float newmove;
     Vector3 BackupPosition;
     Animator anim;
 
     
     // Use this for initialization
     void Start () {        
         anim = GetComponent<Animator> ();
         originalmove = 1f;
     }
 
     // Update is called once per frame
     void FixedUpdate () {
         grounded = Physics2D.OverlapCircle (GroundCheck.position, groundRadius, whatIsGround);
         if (this.transform.position.x < player.transform.position.x)
                         newmove = originalmove;
         
         if (this.transform.position.x > player.transform.position.x)
                         newmove = originalmove * -1;
 
         rigidbody2D.velocity = new Vector2 (newmove, rigidbody2D.velocity.y);
 
         anim.SetFloat("Speed",Mathf.Abs(newmove));
         if (newmove > 0 && !facingRight)
             Flip ();
         
         if (newmove < 0 && facingRight)
             Flip ();
         
 
         
         if (Dead)
             Die ();
 
         if (!grounded)
                         this.transform.position = BackupPosition;
 
         BackupPosition = this.transform.position;
         
     }
     void Flip()
     {
         facingRight = !facingRight;
         Vector3 theScale = transform.localScale;
         theScale.x *= -1;
         transform.localScale = theScale;
     }
     
     void Die()
     {
 
     }
 }

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

2 Replies

· Add your reply
  • Sort: 
avatar image
6
Best Answer

Answer by DarKTower · Jul 09, 2014 at 03:36 AM

A couple things you should check for:

  • Make sure the Enemy is spawned (Using Instantiate?) on a Z point that is viewable by the camera. A couple times this has happened and it's because I spawn something on the same Z position that the Camera is on (Usually -10 or something), instead of spawning at 0 or something more than -10.

  • Make sure the Enemy's Layer has not been set to something that the Camera does not render. This is highly unlikely, but it could've happened.

  • Check that the Sprite Renderer's checkbox is enabled, and that nowhere you set renderer.enabled to false. I don't see it in your code, so this is highly unlikely.

It's most likely the first one, but if it's not any of the above then I suggest somebody more knowledgeable with Unity answer your question than simple old me.

Comment
Add comment · Show 2 · 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 Detinator10 · Jul 09, 2014 at 05:09 PM 0
Share

thank you so much! I always forget that even in Unity2D I have to deal with the Z axis

avatar image ccrome · Dec 20, 2016 at 07:09 AM 0
Share

Thanks! That did the trick: Vector3 pos = Camera.main.ScreenToWorldPoint (Input.mousePosition); pos.z = 0; <--- By adding this, the objects became visible Instantiate (wheelCW, pos, Quaternion.Euler (0, 0, 0));

avatar image
1

Answer by purnjay · Jun 10, 2016 at 12:10 PM

Go to the camera and change the clipping planes near to something like -67

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

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

24 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

Related Questions

SpriteRenderer draw only part of the sprite? 1 Answer

Why do my GameObjects have a flickering line above them? 2 Answers

Unity streching sprite gameobject to fit two positions. 1 Answer

Sprite Mask that affects only the childrens of a GameObject 5 Answers

Occlusion Culling for 2D sprite (SpriteRenderer) 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