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 mike1233 · Feb 05, 2017 at 12:55 PM · scripting problem2d gamescreencollider2dbackgrounds

SImple but IMPOSSIBLE Enemies keep dying way ahead of time !

my enemies keep dying way ahead of time ! this is because I have a left screen collider wall that kills the enemies when they touch/leave the screen , but I need the repeat background so that the background scrolls and I need to kill the enemies when they touch the screen walls

let me explain- I have a 2d background that repeats , and since I have colliders in the scene on the background walls It kills the enemies at wrong times for example when some enemies reach the middle ,and beginning etc of the screen they die because the repeat background is repeating

so what do I do here? I need both
the screen colliders and I need the repeat scrolling background , this is a tough situation - 2d game

so again please understand the problem here- I need both these things but clearly this is a very tricky situation -

please assist me thank you very much

here is the background scroll script ,

 using UnityEngine;
 using System.Collections;
 
 public class bgscroll : MonoBehaviour {
 
 
     public float speed = 0.2f;
 
 
     // Use this for initialization
     void Start () {
     
     }
     
     // Update is called once per frame
     void Update () {
         Vector2 offset = new Vector2 (Time.time * speed, 0);
         GetComponent<Renderer>().material.mainTextureOffset = offset;
     }
 }
 --------------------------------SCRIPT 2
 using System.Collections;
  using System.Collections.Generic;
  using UnityEngine;
  
  public class BulletDestroyScript : MonoBehaviour {
  
  
      void OnEnable()
      {
          Invoke ("Destroy", 7.6f);
      }
      void Destroy()
      {
          gameObject.SetActive(false);
      }
      void OnDisable()
      {
          CancelInvoke();
      }
  }

===============SCRIPT 3

 using System.Collections;
  
  [RequireComponent(typeof(AudioSource))]
  public class mandedd : MonoBehaviour {
  
      public AudioClip pop1;
      public AudioClip boing;
      AudioSource audio;
           Animator anim;                 
  
      void Start()
          {
          audio = GetComponent<AudioSource>();
  
              anim = GetComponent<Animator> ();
  
          }
          void OnCollisionEnter2D(Collision2D other)
      {
  
  if (other.gameObject.tag == "Player" || other.gameObject.tag == "Wall" ) 
  {
      anim.Play("mansded");
      anim.SetTrigger("Die");
      GetComponent<AudioSource> ().Play ();
          audio.PlayOneShot(pop1, 0.7F);
              DeathWatch.ReportDeath ();
  }
  else if (other.gameObject.tag == "cat" || other.gameObject.tag == "cats" ) 
  {
              anim.Play("manded");
              anim.SetTrigger("Die");
              GetComponent<AudioSource> ().Play ();
              audio.PlayOneShot(boing, 0.7F);
              DeathWatch.ReportDeath ();
  }
  
      }
  }
  


Comment
Add comment · Show 5
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 PizzaPie · Feb 05, 2017 at 02:15 PM 0
Share

You got to post the code that kills the enemies othwerwise nobody will be able to help you. Also some info about the colliders, are they triggers?

avatar image mike1233 PizzaPie · Feb 05, 2017 at 02:55 PM 0
Share
 using System.Collections;
 
 [RequireComponent(typeof(AudioSource))]
 public class mandedd : $$anonymous$$onoBehaviour {
 
     public AudioClip pop1;
     public AudioClip boing;
     AudioSource audio;
          Animator anim;                 
 
     void Start()
         {
         audio = GetComponent<AudioSource>();
 
             anim = GetComponent<Animator> ();
 
         }
         void OnCollisionEnter2D(Collision2D other)
     {
 
 if (other.gameObject.tag == "Player" || other.gameObject.tag == "Wall" ) 
 {
     anim.Play("mansded");
     anim.SetTrigger("Die");
     GetComponent<AudioSource> ().Play ();
         audio.PlayOneShot(pop1, 0.7F);
             DeathWatch.ReportDeath ();
 }
 else if (other.gameObject.tag == "cat" || other.gameObject.tag == "cats" ) 
 {
             anim.Play("manded");
             anim.SetTrigger("Die");
             GetComponent<AudioSource> ().Play ();
             audio.PlayOneShot(boing, 0.7F);
             DeathWatch.ReportDeath ();
 }
 
     }
 }
 
avatar image mike1233 PizzaPie · Feb 05, 2017 at 03:22 PM 0
Share

and here is the other enemy kill script on the enemy

there are 2 scripts as u see one is kill after certain amount of time after they are spawned and hit wall

don't get confused the enemy is named "bullet"

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class BulletDestroyScript : $$anonymous$$onoBehaviour {
 
 
     void OnEnable()
     {
         Invoke ("Destroy", 7.6f);
     }
     void Destroy()
     {
         gameObject.SetActive(false);
     }
     void OnDisable()
     {
         CancelInvoke();
     }
 }
 
 
avatar image PizzaPie mike1233 · Feb 05, 2017 at 07:29 PM 0
Share

is the background wall tagged as wall? if yes that s most probably causing the problem. The code seems fine.

avatar image Chikari · Feb 05, 2017 at 04:45 PM 0
Share

What about putting the colliders in a separate game object that does not move with the background?

0 Replies

· Add your reply
  • Sort: 

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

118 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

Related Questions

Gameobject Gravity 2D Script 0 Answers

Help with making an object dodge other objects? 0 Answers

Player should turn in the direction the player is running. (2D Game) 0 Answers

Correct Call function On Gui ? 0 Answers

IsTouchingLayers dont work : 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