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
0
Question by Mack2fire · Apr 17, 2018 at 03:12 PM · errorunity 2denemymovement scriptvoid

Make enemy object move left or right direction position,How to move the enemies

I'm a beginner programmer so I'm not sure how to approach this line of code. The error says something about"unity local function not available in c#4 please update" I'm using an older version of Unity which probably why it shows this error.

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class Enemy_move : MonoBehaviour {
 
     public int enemySpeed;
     public int XMoveDirection;
     Rigidbody2D rigid2D;
 
     void Start()
     {
         rigid2D = GetComponent<Rigidbody2D>();
     }
 
     // Update is called once per frame
     void Update () {
         RaycastHit2D hit = Physics2D.Raycast(transform.position, new Vector2(XMoveDirection, 0));
         rigid2D.velocity = new Vector2 (XMoveDirection, 0 ) * enemySpeed;
         // gameObject.GetComponent<Rigidbody2D>().velocity = new Vector2(XMoveDirection, 0) * 
         enemySpeed;
 
         if (hit.distance < 0.7f && hit.collider != null)
         {
             // Flip();
             if (hit.collider.tag == "Player")
             {
                 Destroy(hit.collider.gameObject);
             }
         } 
         
         /*
         void Flip()
         {
             if (XMoveDirection > 0)
             {
                 XMoveDirection = -1;
             }    
             else
             {
                 XMoveDirection = 1;
             }
         }
         */  
     }
 }
 




,I'm a beginner programmer so I'm not sure how to approach this line of code. The error says something about"unity local function not available in c#4 please update" I'm using an older version of Unity which probably why it shows this error.

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class Enemy_move : MonoBehaviour {
 
     public int enemySpeed;
     public int XMoveDirection;
     Rigidbody2D rigid2D;
 
     void Start()
     {
         rigid2D = GetComponent<Rigidbody2D>();
     }
 
     // Update is called once per frame
     void Update () {
         RaycastHit2D hit = Physics2D.Raycast(transform.position, new Vector2(XMoveDirection, 0));
         rigid2D.velocity = new Vector2 (XMoveDirection, 0 ) * enemySpeed;
         // gameObject.GetComponent<Rigidbody2D>().velocity = new Vector2(XMoveDirection, 0) * 
         enemySpeed;
 
         if (hit.distance < 0.7f && hit.collider != null)
         {
             // Flip();
             if (hit.collider.tag == "Player")
             {
                 Destroy(hit.collider.gameObject);
             }
         } 
         
         /*
         void Flip()
         {
             if (XMoveDirection > 0)
             {
                 XMoveDirection = -1;
             }    
             else
             {
                 XMoveDirection = 1;
             }
         }
         */
         
         
     }
 }
 



Comment
Add comment · Show 3
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 Mack2fire · Apr 17, 2018 at 03:15 PM 0
Share

The error code is on line 33 that has void Flip()

avatar image TreyH Mack2fire · Apr 17, 2018 at 03:24 PM 0
Share

You're declaring Flip() inside of Update(). That isn't allowed in this version of .NET / C#.

Your question header isn't related to the actual question, and this forum isn't the place for basic C# questions. :-\

avatar image Mack2fire · Apr 17, 2018 at 03:39 PM 0
Share

The enemy object moves but like goes to the left side of the wall and stay on there. I try to make the enemy object move to the right and left between the two walls but might have to change something in the update for the enemy object.

1 Reply

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

Answer by Mack2fire · Apr 17, 2018 at 03:26 PM

Sorry about that. I always post something in the wrong place just like in Game Maker Studio's page.

Comment
Add comment · Show 3 · 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 Mack2fire · Apr 17, 2018 at 03:28 PM 0
Share

But the first time I do that since I'm new here. And could you help me find a place to post this question so that I do not post it here?

avatar image TreyH · Apr 17, 2018 at 03:28 PM 0
Share

Questions are always valid, so we're here to help your continued learning! But some places are better than others for certain questions. :-)

avatar image Mack2fire · Apr 17, 2018 at 03:35 PM 0
Share

Yes, It did stop having that error thank you so much. I'm still trying to figure out how to make the enemy object movement between the two wall object I had put in the scene.

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

103 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

Related Questions

topdown shooter unity 2 Answers

Health below zero but shows negative numbers 1 Answer

Simple Enemy AI not working : NullReferenceException: Object reference not set to an instance of an object 2 Answers

Why wont my attack script get the data from my movement script (error)? 1 Answer

How to move 2D enemy AI's along the x-Axis? 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