Here is my code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ThirdPersonMovement : MonoBehaviour
{
public CharacterController controller;
public float speed = 6f;
public float turnSmoothTime = 0.1f;
public Transform cam;
private float verticalVelocity;
private float gravity = 14.0f;
private float jumpForce = 10.0f;
float turnSmoothVelocity;
// Update is called once per frame
void Update()
{
float horizontal = Input.GetAxisRaw("Horizontal");
float vertical = Input.GetAxisRaw("Vertical");
Vector3 direction = new Vector3(horizontal, 0f, vertical).normalized;
if (direction.magnitude >= 0.1f)
{
float targetAngle = Mathf.Atan2(direction.x, direction.z) * Mathf.Rad2Deg + cam.eulerAngles.y;
float angle = Mathf.SmoothDampAngle(transform.eulerAngles.y, targetAngle, ref turnSmoothVelocity, turnSmoothTime);
transform.rotation = Quaternion.Euler(0f, angle, 0f);
Vector3 moveDir = Quaternion.Euler(0f, targetAngle, 0f) * Vector3.forward;
controller.Move(moveDir.normalized * speed * Time.deltaTime);
}
if (controller.isGrounded)
{
verticalVelocity = -gravity * Time.deltaTime;
if (Input.getKeyDown(KeyCode.Space))
{
verticalVelocity = jumpForce;
}
}
else
{
verticalVelocity -= gravity * Time.deltaTime;
}
Vector3 moveVector = Vector3.zero;
moveVector.x = Input.getAxis("Horizontal") * speed;
moveVector.y = verticalVelocity;
moveVector.z = Input.getAxis("Vertical") * speed;
controller.Move(moveVector * Time.deltaTime);
}
}
It has been giving me this error for a couple weeks and I can’t figure it out.
I’ve tried seeing if anybody else has had any issues and looking back at how others have overcome this issue, but nothing seems to be working.
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.
По туториалу собираю 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;
}
}
}
}
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
Содержание
- Как исправить ошибки 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’ это целиком ошибка. Помогите пожалуйста.
Источник
Assets/Scripts/Player_Script.cs(16,33): error CS0117: `UnityEngine.KeyCode’ does not contain a definition for `�’.
Вот сам скрипт
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Player_Script : MonoBehaviour {
public float x;
public float y;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update ()
{ if(Input.GetKeyDown(KeyCode.С)) {
gameObject.GetComponent<Animator>().SetTrigger («Crouch»);
}
if(Input.GetKeyUp(KeyCode.C)) {
gameObject.GetComponent<Animator>().SetTrigger («Idle»);
}
if(Input.GetKeyDown(KeyCode.LeftShift)) {
gameObject.GetComponent<Animator>().SetTrigger («D»);
}
if(Input.GetKeyDown(KeyCode.LeftShift)) {
gameObject.GetComponent<Animator>().SetTrigger («Dive»);
}
if(Input.GetKeyDown(KeyCode.Space)) {
gameObject.GetComponent<Animator>().SetTrigger («Jump»);
}
if(Input.GetKeyDown (KeyCode.Mouse0)){
gameObject.GetComponent<Animator>().SetTrigger («Attack»);
}
x = Input.GetAxis(«Vertical»);
y = Input.GetAxis(«Horizontal»);
if (Input.GetKey (KeyCode.W))
transform.rotation = Quaternion.Lerp (transform.rotation, Quaternion.Euler (0, transform.rotation.y, 0), 0.2f);
if (Input.GetKey (KeyCode.S))
transform.rotation = Quaternion.Lerp (transform.rotation, Quaternion.Euler (0, transform.rotation.y + 180, 0), 0.2f);
if (Input.GetKey (KeyCode.A))
transform.rotation = Quaternion.Lerp (transform.rotation, Quaternion.Euler (0, transform.rotation.y — 90, 0), 0.2f);
if (Input.GetKey (KeyCode.D))
transform.rotation = Quaternion.Lerp (transform.rotation, Quaternion.Euler (0, transform.rotation.y + 90, 0), 0.2f);
}
void FixedUpdate(){
gameObject.GetComponent<Animator> ().SetFloat («Speed», x, 0.1f,Time.deltaTime);
gameObject.GetComponent<Animator> ().SetFloat («Direction», y, 0.1f,Time.deltaTime);
}
}
Добавлено (06 Июня 2018, 15:52)
———————————————
проблема решена
Кошка танцует до утра
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and
privacy statement. We’ll occasionally send you account related emails.
Already on GitHub?
Sign in
to your account
Comments
I am upgrading from Google Play Services from v 0.9.01 to 0.9.20 in unity 4.5, but I am getting this error Assets/GooglePlayGames/Editor/GPGSPostBuild.cs(41,39): error CS0117: UnityEditor.BuildTarget' does not contain a definition for
iOS’
I am developing for android not IOS, any idea how to fix this?
I solved this problem by installing the latest Unity3d. But still unable to get the google play services setup on the main menu of the editor.
After you updated, can you remove the GooglePlayGames folder in the Assets folder, and reimport the package? The menus should be under Windows/Google Play Games. (We moved them recently to be a better citizen of the Unity editor). If they don’t show up, there must be still some errors in the console?
yes found it, it is under Windows/Google Play Games. I did not delete the GooglePlayGames folder. using the 0.9.20 version as it is. I deleted the old version 0.9.01 completely with all its files and folders before importing the new one. Thanks claywilkinson
well google play games for pc? i have tried because i have the same issue but:
error CS0117: ‘BuildTarget’ does not contain a definition for ‘GameCoreXboxSeries’
but i dont have that windows/googlePlayGames folder.
appreciate your help.
У меня тожа такая ошибка
ошибка CS0117: «buildTarget» не содержит определения для «GameCoreXboxSeries»
Сейчас пробую обновить до новой версии, может поможет.
Если кто-то знает решение напишите пожалуйста!
Решил вопрос.
Установил новую версию Unity запустил проект на ней