Hello there.
I am a beginner with Unity and Scripting, and i’m facing a problem wich i can’t find a solution
here is the code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Player : MonoBehaviour
{
public float speed;
LayerMask obstacleMask;
Vector2 targetPos;
Transform GFX;
float flipX;
bool isMoving;
void Start()
{
obstacleMask = LayerMask.GetMask(“Wall”, “Enemy”);
GFX = GetComponentInChildren().transform;
flipX = GFX.localScale.x;
}
void Update()
{
float horz = System.Math.Sign(Input.GetAxisRaw(“Horizontal”));
float vert = System.Math.Sign(Input.GetAxisRaw(“Vertical”));
if (Mathf.Abs(horz) > 0) if (Mathf.Abs(vert) > 0)
{
if (Mathf.Abs(horz) > 0)
{
GFX.localScale = new Vector2(flipX * horz, GFX.localScale.y);
}
if (!isMoving)
{
if (Math.Abs(horz) > 0)
{
targetPos = new Vector2(transform.position.x + horz, transform.position.y);
}
else if (Math.Abs(vert) > 0)
{
targetPos = new Vector2(transform.position.x, transform.position.y + vert);
}
//check for collisions
Vector2 hitSize = Vector2.one * 0.8f;
Collider2D hit = Physics2S.OverLapBox(targetPos, hitSize, 0, obstacleMask);
if (!hit)
{
StartCoroutine(Smoothmove());
}
}
}
}
iEnumerator Smoothmove()
{
isMoving = true;
while(Vector2.Distance(transform.position, targetPos) > 0.01f)
{
transform.position = Vector2.MoveTowards(transform.position, targetPos, speed * Time.DeltaTime);
yield return null;
}
transform.position = targetPos;
isMoving = false;
}
}
Unity shows me that error CS0246: The type or namespace name ‘iEnumerator’ could not be found (are you missing a using directive or an assembly reference?)
Do anyone more experienced with this help me?
Thanks.