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
-1
Question by flatalex123 · May 11, 2017 at 03:00 AM · c#unity 5error

Small error C#

Hello

I have been trying to get the following code to work but i have been getting this error Assets/BreakingGlass.cs(17,4): error CS0103: The name go does not exist in the current context

I have no clue how to fix this. Thanks

 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
 
 
 public class BreakingGlass : MonoBehaviour {
     public GameObject PortalB;
     public bool Active = false;
     void Update()    {
 
     }
 
     void OnTriggerEnter(Collider other)
     {
 
         if (other.gameObject.tag == "Wrench") {
             PortalB.SetActive(false);
 
             GameObject[] gos = GameObject.FindGameObjectsWithTag ("Glass");
             Active = true;
 
             foreach (GameObject go in gos);
             gos.Rigidbody.iskinematic = false;    
             PortalB.SetActive(false);
 
             for(int i=0; i<gos.Length; i++)
             {
                 for(int j=0; j<gos[i].transform.childCount; j++)
                 {
                     gos[i].transform.GetChild(j).gameObject.active = false;
                 }
             }
         }
     }
 
 }
 

Edit: I did a test and when i threw the wrench at the object nothing happens. Can i get help with this to please

Comment
Add comment · Show 1
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 RobAnthem · May 11, 2017 at 03:29 AM 0
Share

Well

              foreach (GameObject go in gos);

Doesn't do anything, probably your error. A foreach loop works like any loop, it would look like this.

 foreach (GameObject go in gos)
 {
     go.doStuff;
 }

2 Replies

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

Answer by TeohRIK · May 11, 2017 at 03:29 AM

 using System.Collections;
  using System.Collections.Generic;
  using UnityEngine;
  
  public class BreakGlass2 : MonoBehaviour 
  {
      public Rigidbody body;
      public Rigidbody[] Shads;
  
      public void OnCollisionEnter(Collision other)
      {
          if (other.gameObject.tag == "Wrench")
          {
              Debug.Log ("Hi");
              foreach (Rigidbody body in Shads) {
                  body.isKinematic = false;
              }
          }
      }
          
  }

Comment
Add comment · Show 22 · 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 flatalex123 · May 11, 2017 at 04:41 AM 0
Share

Thanks for the replay but im still getting this error Assets/BreakingGlass.cs(20,35): error CS1061: Type UnityEngine.Rigidbody does not contain a definition for iskinematic and no extension method iskinematic of type UnityEngine.Rigidbody could be found. Are you missing an assembly reference?

avatar image TeohRIK flatalex123 · May 11, 2017 at 04:48 AM 0
Share

opps...forget to change the iskinematic to is$$anonymous$$inematic and I fixed some mistake

foreach (GameObject go in gos){ Rigidbody rb = go.GetComponent<Rigidbody>(); if(rb != null) rb.is$$anonymous$$inematic = false; else Debug.Log("Rigidbody is Null"); }

avatar image RobAnthem · May 11, 2017 at 04:42 AM 0
Share

That is because he missed the capital $$anonymous$$ in is$$anonymous$$inematic. Change iskinematic to is$$anonymous$$inematic. @walaoRI$$anonymous$$I nvm sorry, I see that you only copied the OP's code and it was not your missing the capital, but his. Either way, problem solved :)

avatar image flatalex123 · May 11, 2017 at 05:00 AM 0
Share

Thanks for all the help. I am no longer getting any errors but nothing seems to be happing when the bullet coll with the window. Any ideas? ps the right tag is set on the object

avatar image RobAnthem flatalex123 · May 11, 2017 at 05:07 AM 0
Share

Well now that you mention the intent of this script, then it makes zero sense how you set it up... What is going on? Why do you GameObject.FindGameObjectsWithTag ("Glass");? If your bullet hits the glass, either the bullet or the glass should handle the collision. Assu$$anonymous$$g it is the glass handling it, because the collision is checking for a bullet, why are you searching for glass? It should look more like this.

 public class Glass : $$anonymous$$onoBehaviour
 {
     public Rigidbody body;
 }

then your window

 public class Window : $$anonymous$$onoBehaviour
 {
     public Glass[] glass;
     public void OnCollisionEnter(Collider other)
     {
         if (other.gameObject.tag == "Bullet")
         {
             foreach (Glass _glass in glass)
             {
                 glass.body.is$$anonymous$$inematic = false;
             }
         }
     }
 }


avatar image flatalex123 RobAnthem · May 11, 2017 at 05:56 AM 0
Share

$$anonymous$$y window is a solid see through object that will be deleted and replaced by a shattered window (when the bullet hits it) with about 200 children so i gave them the tag window so i could turn off is$$anonymous$$inematic at the same time for all of them

Show more comments
Show more comments
avatar image RobAnthem flatalex123 · May 11, 2017 at 06:20 AM 0
Share

You need to create the Glass class first, then you can just use the Add Componenet button.

Actually, you could just add a Rigidbody[] glass field to your Window class, and then lock the window inspector, mass select the glass pieces, and drag and drop them into the array.

Then you can just iterated the rigidbodies like so

 foreach (Rigidbody body in glass)
 {
     body.is$$anonymous$$inematic = false;
 }

This is probably the most efficient thing to do.

avatar image flatalex123 RobAnthem · May 11, 2017 at 06:22 AM 0
Share

Sorry i don't really know what i am meant to do

Show more comments
avatar image TeohRIK flatalex123 · May 11, 2017 at 09:41 AM 0
Share

Will giv you some tips later, juz come b from work now going for some running. whats your current country time?

avatar image TeohRIK TeohRIK · May 11, 2017 at 09:44 AM 1
Share

@flatalex123 use Collision not Collider, collider only for OnTriggerEnter, for OnCollisionEnter you need to use Collision

 public void OnCollisionEnter(Collision other)
      {
          if (other.gameObject.tag == "Wrench")
          {
              Debug.Log ("Hi");
              foreach (Rigidbody body in Shads) {
                  body.is$$anonymous$$inematic = false;
              }
          }
      }
Show more comments
Show more comments
avatar image
0

Answer by Kristinosis · May 11, 2017 at 01:58 PM

You need to get rid of the semi-colon after your foreach loop. "go" doesn't exist outside of the loop and the semi-colon is ending the loop statement. :)

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

126 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

Related Questions

Unity 5 UNet Spawn as Child. 1 Answer

The name 'TrackManager' does not exist in the current context [Unity Vuforia Ground Plane Project] 0 Answers

the object of type rigidbody has been destroyed 3 Answers

Error building Player because scripts had compiler errors 2 Answers

script does not update inspector? 3 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