Пожалуйста по одной проблеме. Я ввёл строку :
Collider2D[] colliders = Physics2D.OverLapCircleAll(groundCheck.position, 0.2f);
А программа отвечает:
"error CS0117:'Physics2D' does not contain a definition for 'OverLapCircleAll'"
karashal
5044 серебряных знака21 бронзовый знак
задан 23 июн 2021 в 4:52
6
Функция называется OverlapCircleAll, регистр букв важен.
У вас же OverLap
с большой буквой L
.
ответ дан 23 июн 2021 в 5:32
CrazyElfCrazyElf
62.4k5 золотых знаков19 серебряных знаков47 бронзовых знаков
C# Compiler Error
CS0117 – ‘type’ does not contain a definition for ‘identifier’
Reason for the Error
This error can be seen when you are trying to reference an identifier that does not exist for that type. An example of this when you are trying to access a member using base. where the identifier doesnot exist in the base class.
For example, the below C# code snippet results with the CS0117 error because the the identifier Field1 is accesses using base.Field1 but it doesnot exist in the base class “Class1”.
namespace DeveloperPublishNamespace { public class Class1 { } public class Class2 : Class1 { public Class2() { base.Field1 = 1; } } public class DeveloperPublish { public static void Main() { } } }
Error CS0117 ‘Class1’ does not contain a definition for ‘Field1’ ConsoleApp1 C:UsersSenthilsourcereposConsoleApp1ConsoleApp1Program.cs 11 Active
Solution
To fix the error code CS0117, remove the references that you are trying to make which is not defined in the base class.
using System.Collections;
public class Player : MonoBehaviour
{
Rigidbody2D rb;
public float speed;
public float jumpHeight;
public Transform groundCheck;
bool isGrounded;
Animator anim;
int curHp;
int maxHp = 3;
bool isHit = false;
public Main main;
public bool key = false;
// Start is called before the first frame update
void Start()
{
rb = GetComponent<Rigidbody2D>();
anim = GetComponent<Animator>();
curHp = maxHp;
}
// Update is called once per frame
void Update()
{
CheckGround();
if (Input.GetAxis(«Horizontal») == 0 && (isGrounded))
{
anim.SetInteger(«State», 1);
}
else
{
Flip();
if (isGrounded)
anim.SetInteger(«State», 2);
}
}
void FixedUpdate()
{
rb.velocity = new Vector2(Input.GetAxis(«Horizontal») * speed, rb.velocity.y);
if (Input.GetKeyDown(KeyCode.Space) && isGrounded)
rb.AddForce(transform.up * jumpHeight, ForceMode2D.Impulse);
}
void Flip()
{
if (Input.GetAxis(«Horizontal») > 0)
transform.localRotation = Quaternion.Euler(0, 0, 0);
if (Input.GetAxis(«Horizontal») < 0)
transform.localRotation = Quaternion.Euler(0, 180, 0);
}
56 void CheckGround()
{
Collider2D[] colliders = Physics2D.OverlapCircleAll(groundCheck.position, 0.2f);
59 isGrounded = colliders.Length > 1;
if (!isGrounded)
anim.SetInteger(«State», 3);
}
public void RecountHp(int deltaHp)
{
curHp = curHp + deltaHp;
if (deltaHp < 0)
{
StopCoroutine(OnHit());
isHit = true;
StartCoroutine(OnHit());
}
print(curHp);
if (curHp <= 0)
{
GetComponent<CapsuleCollider2D>().enabled = false;
Invoke(«Lose», 1.5f);
}
}
//Корутина, для того чтобы персонаж менял цвет при нанесении урона или смерти
IEnumerator OnHit()
{
if (isHit)
GetComponent<SpriteRenderer>().color = new Color(1f, GetComponent<SpriteRenderer>().color.g — 0.04f, GetComponent<SpriteRenderer>().color.b — 0.04f);
else
GetComponent<SpriteRenderer>().color = new Color(1f, GetComponent<SpriteRenderer>().color.g + 0.04f, GetComponent<SpriteRenderer>().color.b + 0.04f);
if (GetComponent<SpriteRenderer>().color.g == 1f)
StopCoroutine(OnHit());
if (GetComponent<SpriteRenderer>().color.g <= 0)
isHit = false;
yield return new WaitForSeconds(0.02f);
StartCoroutine(OnHit());
}
void Lose()
{
main.GetComponent<Main>().Lose();
}
void OnTriggerEnter2D(Collider2D collision)
{
if (collision.gameObject.tag == «key»)
{
Destroy(collision.gameObject);
key = true;
}
110 if (collision.gameObject.tag == «Door»)
{
if (collision.gameObject.GetComponent<Door>().isOpen)
113 collision.gameObject.GetComponent<Door>().Teleport(gameObject);
else if (key)
collision.gameObject.GetComponent<Door>().Unlock();
}
}
}
I’m a complete beginner in Unity 3D, and I’m following a video training. In the video the instructor uses the following code to open a door using raycast:
using UnityEngine;
using System.Collections;
public class HelloRaycasting : MonoBehaviour {
bool doorClosed = true;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
Vector3 backward = new Vector3 ( 0, 0, -1);
Vector3 origin = this.gameObject.transform.position;
if (Physics.Raycast( origin, backward, 1f) && doorClosed) {
doorClosed = false;
GameObject.Find ("Left_Quad").transform.Translate ( new Vector3(-.8f, 0, 0));
GameObject.Find ("Right_Quad").transform.Translate ( new Vector3(.8f, 0, 0));
}
}
}
It works just fine for him. But when I try to run this on my computer I get this error:
Assets/HelloRaycasting.cs(20,29): error CS0117: ‘Physics’ does not
contain a definition for ‘Raycast’
In the end I’m not able to access none of the properties and methods of the Physics class.
I’m using Unity 5.3.2f1 (64-bit). What am I doing wrong?
Laurean 0 / 0 / 0 Регистрация: 08.07.2020 Сообщений: 3 |
||||
1 |
||||
13.07.2020, 20:38. Показов 4847. Ответов 1 Метки unity 3d, unity (Все метки)
Unity ошибка error CS0117: ‘Transform’ does not contain a definition for ‘positon’
__________________
0 |
2496 / 1512 / 803 Регистрация: 23.02.2019 Сообщений: 3,689 |
|
13.07.2020, 21:02 |
2 |
Решение Но у transform действительно нет свойства positon
1 |
I’m a beginner, but I’m thinking of making a 2D shooter.
It worked correctly until then, but when I incorporated a command to push the button of my ammunition, I threw an error.
I investigated variously, but I am not sure how to solve my problem, so I am in trouble.
Please lend me your wisdom.
error CS0117:'KeyCode' does not contain a definition for'z'
Applicable source code
public class testP: MonoBehaviour
{
public Transform firing position;// connection with bullet
void Update()
{
float x = Input.GetAxis("Horizontal");
float y = Input.GetAxis("Vertical");
transform.position += new Vector3(x, y, 0) * Time.deltaTime * 4f;
if (Input.GetKeyDown(KeyCode.z))
{
Debug.Log("z");
}
}
}
What I tried
I typed it while checking each one, and tried to google the error message.
I carefully checked the commands, including capital letters, so I don’t think it’s wrong.
I changed to Space because I thought that the z key itself was useless, but this was the same.
if (Input.GetKeyDown(KeyCode.z)) {Debug.Log(«z»);}
I was able to play it just before I typed it in, and when I erased it, I confirmed that I was able to play it again.
There is no doubt that this is the cause…
Supplementary information (FW/tool version, etc.)
2020.1.0f1