Quantcast
Channel: Questions in topic: "enemy"
Viewing all articles
Browse latest Browse all 1488

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

$
0
0
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(); } // 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().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(); } // 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().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; } } */ } }

Viewing all articles
Browse latest Browse all 1488

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>