Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 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 bracciata · Aug 04, 2015 at 03:00 AM · c#prefabscript.object

Script on Prefab is not changeable without changing all other instaniated objects

I'm sorry for crappy explanation but maybe by telling you whats happening and showing some scripts somebody would understand. I have these scripts attached to a bullet prefab which I instantiate on mouse down and have tried lots of things all of my methods are show because I turned them into comments. Heres the bullets script. Currently the bullets not moving and I think the problem may be I can't attach the public movescript move in the bullet script too an in scene object which is the player, how would I go about doing this.

     public EnemyScripts enemyscript;
     public MoveScript Move;
     //public GameObject Enemy;
     public Vector2 RightBulletVelocity = new Vector2 (30, 0);
     public Vector2 LeftBulletVelocity = new Vector2 (-30, 0);
     public GameObject mafia;
     public float speed = 30f;
 public bool BulletLeft =  false;
     public bool BulletRight = false;
     //Vector3 CurrPos = transform.position;
 
     //public GameObject block;
     // Use this for initialization
     public void BulletCheck (){
         if (Move.LookingRighty = true) {
             }
     }
     void Start () {
         Destroy(gameObject, 3);
         Debug.Log ("bullet has been shot");
         //CurrPos.x += 0.5f;
         //Rigidbody2D RB = GetComponent<Rigidbody2D> ();
         //RB.velocity = new Vector2 (speed, RB.velocity.y);
 
         //if (Move.LookingRighty == true) {
         //    Debug.Log("should be shooting right");
         //    BulletLeft = false;
         //    BulletRight = true;
             // transform posistion +.5
             //GetComponent<Rigidbody2D>().velocity = BulletVelocity;
         //} else {
             //GetComponent<Rigidbody2D>().velocity = BulletVelocity;
             //transform.posistion -.5
         //    BulletLeft = true;
         //    BulletRight = false;
         //    Debug.Log("should be shooting left");
         //}
         //transform.position.x += 0.5f;
         //transform.position = CurrPos;
 
         //transform.position.x += 1;
     }
     void OnCollision2D (Collision col){
 
 
          if (col.gameObject.name == "Enemy") {
             enemyscript.kill ();
             Destroy(gameObject);
         } else {
             Destroy(gameObject);}
     }
     // Update is called once per frame
     void OnBecameInvisible(){
         Destroy (gameObject);
     }
     void Update () {
         if (BulletLeft == true) {
             GetComponent<Rigidbody2D> ().velocity = LeftBulletVelocity;
             Debug.Log("bullet left = true");
         }
         if (BulletRight == true) {
             GetComponent<Rigidbody2D> ().velocity = RightBulletVelocity;
             Debug.Log("bulletright = true");
         }
         if (transform.position.x > mafia.transform.position.x + 15) {
             Destroy (gameObject);
         } 
         if (transform.position.x < mafia.transform.position.x - 15) {
             Destroy (gameObject);
         }
     }
 }

Heres my player script

 public void Shoot(){
         PlayerBulletScripts.BulletCheck ();
         if (LookingRighty == true) {
             Rigidbody2D bulletInstance = Instantiate(bullets, transform.position, Quaternion.Euler(new Vector3(0,0,0))) as Rigidbody2D;
             //bulletInstance.velocity = new Vector2(bulletspeed, 0);
             Debug.Log("looking right and shooting");
             PlayerBulletScripts.BulletRight = true;
             PlayerBulletScripts.BulletLeft = false;
             //PlayerBulletScripts.BulletCheck();
         }
         if (LookingLefty == true) {
             Rigidbody2D bulletInstance = Instantiate(bullets, transform.position, Quaternion.Euler(new Vector3(0,0,180f))) as Rigidbody2D;
             //bulletInstance.velocity = new Vector2(-bulletspeed, 0);
             Debug.Log("looking left and shooting");
             PlayerBulletScripts.BulletLeft = true;
             PlayerBulletScripts.BulletRight = false;
             //PlayerBulletScripts.BulletCheck();
         }
         Debug.Log ("shoot has been called");
 
 
 
     }

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
1

Answer by GiyomuGames · Aug 04, 2015 at 03:04 AM

Why don't you just have bullets with rigid bodies and 0 gravity? Then after you instantiate them you can add a force and they will fly in the direction you want. You won't have to manually handle their movement.

Additionally, if your bullets are very fast then maybe you can use a simple raycast to check if the player is hitting the enemies or not. If you use OnCollision2D on fast objects you may have some trouble where the bullet go through your enemies.

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

Multiple Cars not working 1 Answer

How to destroy instantiated objects. 1 Answer

Deactivating one object trough script deletes all versions of it in scene 1 Answer

How to make two objects with the same directory source got different behaviours 3 Answers

Object over terrain 2 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