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 CodingNoob_ · May 27, 2016 at 06:45 PM · 2d game

I want to alternate between gameobjects by using transforms in c#

I have an error CS0176 for some reason and I don't understand why plz help thanks.

code

using UnityEngine; using System.Collections;

public class MoveMent : MonoBehaviour {

 public float moveSpeed; 
 public float jumpHeight;
 public Transform groundCheck;
 public float groundCheckRadius;
 public LayerMask whatIsGround;
 private bool grounded;
 private bool doubleJumped;


// Game Objects/Transforms I want to alternate.

     public GameObject FirePoint;                      
     public GameObject FirePoint2;                      
     public Transform firePoint;


 private SpriteRenderer mySpriteRenderer;
 public GameObject bullet;


 // Use this for initialization
 void Start () {
 
 }

 void FixedUpdate() {
     grounded = Physics2D.OverlapCircle (groundCheck.position, groundCheckRadius, whatIsGround);
 }


 void Update () {
     if (grounded)
        doubleJumped = false;


     if (Input.GetKeyDown (KeyCode.UpArrow) && grounded) {
         GetComponent<Rigidbody2D>().velocity = new Vector2(GetComponent<Rigidbody2D>().velocity.x, jumpHeight); }

     if (Input.GetKeyDown (KeyCode.UpArrow) && !doubleJumped && !grounded) {
         GetComponent<Rigidbody2D>().velocity = new Vector2(GetComponent<Rigidbody2D>().velocity.x, jumpHeight);
         doubleJumped = true; }
     

     if (Input.GetKey (KeyCode.LeftArrow)) {
         GetComponent<Rigidbody2D>().velocity = new Vector2(-moveSpeed, GetComponent<Rigidbody2D>().velocity.y); 

     
     
     }
         
     if (Input.GetKey (KeyCode.RightArrow)) {
         GetComponent<Rigidbody2D> ().velocity = new Vector2 (moveSpeed, GetComponent<Rigidbody2D> ().velocity.y); 


     }

     if (Input.GetKey (KeyCode.LeftArrow)) {
         mySpriteRenderer.flipX = true;
     
     }

     if (Input.GetKey (KeyCode.RightArrow)) {
         mySpriteRenderer.flipX = false;

     }
     
     if (Input.GetKeyDown(KeyCode.Space)) 
     {
         Instantiate (bullet, firePoint.position, firePoint.rotation);
     }


     //  Error Here, <----------------------------> 

     if (Input.GetKey (KeyCode.LeftArrow)) {
         Transform firePoint = gameObject.Find("FirePoint2");
     }


     if (Input.GetKey (KeyCode.RightArrow)){
         Transform firePoint = gameObject.Find("FirePoint");
             
                     
     }
 // <-----------------------------------> End of error
 
 }

 private void Awake(){
     mySpriteRenderer = GetComponent<SpriteRenderer>();
 
 
 
 
 }



}

Comment
Add comment · Show 2
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 TreyH · May 27, 2016 at 06:57 PM 0
Share

CS0176: Static member 'member' cannot be accessed with an instance reference; qualify it with a type name ins$$anonymous$$d (https://msdn.microsoft.com/en-us/library/zhcxt2bd.aspx),

So, you're likely trying to call a class function or value (defined as Static with respect to the class itself) using an instance of that class.

Given this, is the error being called at:

 gameObject.Find("FirePoint");

If so, this needs to be GameObject (caps) because you need to call the class name.

avatar image TreyH · May 27, 2016 at 06:58 PM 0
Share

Also, you already defined "firePoint" in this scope, so there's no need to write:

 Transform firePoint = gameObject.Find("FirePoint");

delete "Transform"

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by CodingNoob_ · May 27, 2016 at 07:32 PM

Thanks @TreyH I finally fixed it with trial and error :)

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

61 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

Related Questions

Cant edit anything. 0 Answers

HELP!! I don't know how to do the 2Dcharacter jump only once in C#code 0 Answers

Jump Script 2 Answers

Aspect ratio help android 0 Answers

Adding sprites 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