Im trying to show on console when a gameobject collides with another gameobject with collide. I keep getting this error on unity’s console ERROR CS0117, ‘Debug’ does not contain a definition for ‘log’.
- im on mac using .net core
- im using vs code 1.35.1
and unity 2019.3.0a5 - i already have all the usings that i need, but intellisense does not find a definition for my debug or for anything whatsoever, this is frustrating :/
-
i dont have any other .cs file named debug neither
using UnityEngine; using System.Collections; using System.Collections.Generic; using UnityEngine.SceneManagement; public class DeadZone : MonoBehaviour { private void OnCollisionEnter2D(Collision2D collision){ Debug.log("Collision"); } private void OnTriggerEnter2D(Collider2D collision){ Debug.log("Trigger"); } }
i expect a «collision» message in the console of unity when my ball gameobject touches a wall gameobject, both with collider but i only get that error within the console, i also already tried using UnityEngine.Debug.log(); but havent got any success yet…
mjwills
23.2k6 gold badges38 silver badges61 bronze badges
asked Jun 20, 2019 at 5:24
3
You are using Debug.log()
. but you should be using Debug.Log()
. Notice the capitalised «L» on «Log».
By naming convention for C# method names will always start with a capital letter.
If you look at the Unity Docs for Debug.Log you’ll also see in the code examples/title that it uses the capital L
Also judging from your tags you are using Visual Studio. Make sure that intelliSense is turned on, as this should detect and most of the time even automatically fix these kinds of typos for you.
answered Jun 20, 2019 at 6:12
RemyRemy
4,7835 gold badges30 silver badges57 bronze badges
9
По туториалу собираю Tower Defence на Unity для себя и на моменте создания скрипта для башен получаю ошибки CS0117 и CS0122.
Туториал супер наглядный, там просто пишется код и дополнительно объясняется что к чему.
По итогу его написания у человека все работает, у меня ошибки.
Дословно выглядят они так:
1) AssetsScriptsTower.cs(26,41): error CS0117: ‘Enemies’ does not contain a definition for ‘enemies’
2) AssetsScriptsTower.cs(51,21): error CS0122: ‘Enemy.takeDamage(float)’ is inaccessible due to its protection level
Сам Код:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Tower : MonoBehaviour
{
[SerializeField] private float range;
[SerializeField] private float damage;
[SerializeField] private float timeBetweenShots; // Time in seconds between shots
private float nextTimeToShoot;
private GameObject currentTarget;
private void Start()
{
nextTimeToShoot = Time.time;
}
private void updateNearestEnemy()
{
GameObject currentNearestEnemy = null;
float distance = Mathf.Infinity;
foreach(GameObject enemy in Enemies.enemies)
{
float _distance = (transform.position - enemy.transform.position).magnitude;
if (_distance < distance)
{
distance = _distance;
currentNearestEnemy = enemy;
}
}
if (distance <= range)
{
currentTarget = currentNearestEnemy;
}
else
{
currentTarget = null;
}
}
private void shoot()
{
Enemy enemyScript = currentTarget.GetComponent<Enemy>();
enemyScript.takeDamage(damage);
}
private void Update()
{
updateNearestEnemy();
if (Time.time >= nextTimeToShoot)
{
if (currentTarget != null)
{
shoot();
nextTimeToShoot = Time.time + timeBetweenShots;
}
}
}
}
Im trying to show on console when a gameobject collides with another gameobject with collide. I keep getting this error on unity’s console ERROR CS0117, ‘Debug’ does not contain a definition for ‘log’.
- im on mac using .net core
- im using vs code 1.35.1
and unity 2019.3.0a5 - i already have all the usings that i need, but intellisense does not find a definition for my debug or for anything whatsoever, this is frustrating :/
-
i dont have any other .cs file named debug neither
using UnityEngine; using System.Collections; using System.Collections.Generic; using UnityEngine.SceneManagement; public class DeadZone : MonoBehaviour { private void OnCollisionEnter2D(Collision2D collision){ Debug.log("Collision"); } private void OnTriggerEnter2D(Collider2D collision){ Debug.log("Trigger"); } }
i expect a «collision» message in the console of unity when my ball gameobject touches a wall gameobject, both with collider but i only get that error within the console, i also already tried using UnityEngine.Debug.log(); but havent got any success yet…
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.
Содержание
- Как исправить ошибки CS0117 и CS0122?
- Ошибка CS0117 в Unity.
- Ошибка CS0117 в Unity.
Как исправить ошибки CS0117 и CS0122?
По туториалу собираю Tower Defence на Unity для себя и на моменте создания скрипта для башен получаю ошибки CS0117 и CS0122.
Туториал супер наглядный, там просто пишется код и дополнительно объясняется что к чему.
По итогу его написания у человека все работает, у меня ошибки.
Дословно выглядят они так:
1) AssetsScriptsTower.cs(26,41): error CS0117: ‘Enemies’ does not contain a definition for ‘enemies’
2) AssetsScriptsTower.cs(51,21): error CS0122: ‘Enemy.takeDamage(float)’ is inaccessible due to its protection level
- Вопрос задан 13 мая 2022
- 166 просмотров
Простой 1 комментарий
1 — у тебя в классе Enemies нет члена enemies. Возможно его нет совсем, а возможно у тебя опечатка.
2 — у тебя в классе Enemy есть метод takeDamage, но он не публичный
PS: На будущее:
— отмечай комментарием, на какой именно строке сработала ошибка
— не забывай заворачивать код в тег — это сильно упростит чтение для тех, кто попробует решить твой вопрос
— перед тем как задавать вопрос — попробуй загуглить в чём суть ошибки, и попробуй сам решить (CS0117, CS0122)
— перед тем как начинать писать на юнити, лучше всё-таки хоть самые основы C# изучить. Тут как в математике — без понимания простых вещей, ты гарантированно не сможешь понять сложные вещи.
Источник
Ошибка CS0117 в Unity.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class движение : MonoBehaviour
<
public float speed;
public float jumpForce;
public float moveInput;
public Joystick joystick;
private Rigidbody2D rb;
private bool facingRight = true;
private bool isGrounded;
public Transform feetPos;
public float checkRadius;
public LayerMask whatIsGround;
private void Start()
<
rb = GetComponent ();
>
private void FixedUpdate()
<
moveInput = joystick.Horizontal;
rb.velocity = new Vector2(moveInput * speed, rb.velocity.y);
if(facingRight == false && moveInput > 0)
<
Flip();
>
else if(facingRight == true && moveInput = .5f)
<
rb.velocity = Vector2.up * jumpForce;
>
>
void OnCollisionEnter2D(Collision2D shit)
<
if (shit.gameObject.tag == «враг»)
<
ReloadFuckingLevel ();
>
>
void ReloadFuckingLevel()
<
Application.LoadLevel (Application.loadLevel); //здесь ошибка
>
void Flip()
<
facingRight = !facingRight;
Vector3 Scaler = transform.localScale;
Scaler.x *= -1;
transform.localScale = Scaler;
>
>
cs(63,44): error CS0117: ‘Application’ does not contain a definition for ‘loadLevel’ это целиком ошибка. Помогите пожалуйста.
Источник
Ошибка CS0117 в Unity.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class движение : MonoBehaviour
<
public float speed;
public float jumpForce;
public float moveInput;
public Joystick joystick;
private Rigidbody2D rb;
private bool facingRight = true;
private bool isGrounded;
public Transform feetPos;
public float checkRadius;
public LayerMask whatIsGround;
private void Start()
<
rb = GetComponent ();
>
private void FixedUpdate()
<
moveInput = joystick.Horizontal;
rb.velocity = new Vector2(moveInput * speed, rb.velocity.y);
if(facingRight == false && moveInput > 0)
<
Flip();
>
else if(facingRight == true && moveInput = .5f)
<
rb.velocity = Vector2.up * jumpForce;
>
>
void OnCollisionEnter2D(Collision2D shit)
<
if (shit.gameObject.tag == «враг»)
<
ReloadFuckingLevel ();
>
>
void ReloadFuckingLevel()
<
Application.LoadLevel (Application.loadLevel); //здесь ошибка
>
void Flip()
<
facingRight = !facingRight;
Vector3 Scaler = transform.localScale;
Scaler.x *= -1;
transform.localScale = Scaler;
>
>
cs(63,44): error CS0117: ‘Application’ does not contain a definition for ‘loadLevel’ это целиком ошибка. Помогите пожалуйста.
Источник
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