So, I am new to coding in c# and was trying to make the ball appear and launch towards you but it has CS1001 and I am really confused, I would appreciate it if someone could help.
public GameObject("ball");
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
float y = 50;
float dX = y * 0.8f;
// y = (vNotY ^ 2) / 2g
float vNotY = y * 2 * Physics.gravity.y;
vNotY = Mathf.Sqrt(vNotY);
// t = 2 * v0y / g
float time = 2 * vNotY / Physics.gravity.y;
// v = d / t
float vX = dX / time;
Vector3 force = new Vector3(vX, vNotY, 0);
ball.rigidbody.AddForce(force);
}
}
SkryptX
6831 gold badge8 silver badges22 bronze badges
asked May 24, 2020 at 19:34
1
public GameObject("ball");
change to
public GameObject ball;
variable declaration
accessibility class variablename ;
answered May 24, 2020 at 20:02
vasmosvasmos
2,4521 gold badge10 silver badges21 bronze badges
description | title | ms.date | f1_keywords | helpviewer_keywords | ms.assetid |
---|---|---|---|---|---|
Compiler Error CS1001 |
Compiler Error CS1001 |
07/20/2015 |
CS1001 |
CS1001 |
327ad669-9c20-4fe8-a771-234878dbb90e |
Compiler Error CS1001
Identifier expected
You did not supply an identifier. An identifier is the name of a class, struct, namespace, method, variable, and so on, that you provide.
The following example declares a simple class but does not give the class a name:
public class //CS1001 { public int Num { get; set; } void MethodA() {} }
The following sample generates CS1001 because, when declaring an enum, you must specify members:
public class Program { enum Colors { 'a', 'b' // CS1001, 'a' is not a valid int identifier // The following line shows examples of valid identifiers: // Blue, Red, Orange }; public static void Main() { } }
Parameter names are required even if the compiler doesn’t use them, for example, in an interface definition. These parameters are required so that programmers who are consuming the interface know something about what the parameters mean.
interface IMyTest { void TestFunc1(int, int); // CS1001 // Use the following line instead: // void TestFunc1(int a, int b); } class CMyTest : IMyTest { void IMyTest.TestFunc1(int a, int b) { } }
See also
- Operators and expressions
- Types
h6gh 0 / 0 / 0 Регистрация: 27.12.2020 Сообщений: 4 |
||||
1 |
||||
29.12.2020, 13:33. Показов 3458. Ответов 4 Метки unity (Все метки)
__________________
0 |
0 / 0 / 0 Регистрация: 27.12.2020 Сообщений: 4 |
|
31.12.2020, 12:18 [ТС] |
3 |
Можешь нормально помочь, а не эту фигню скидывать?
0 |
Модератор 2383 / 955 / 335 Регистрация: 11.08.2017 Сообщений: 2,980 |
|
31.12.2020, 12:25 |
4 |
h6gh, ответ по теме и уместней некуда. в вашем коде видно полное непонимание основ языка
0 |
16 / 11 / 5 Регистрация: 27.12.2020 Сообщений: 33 |
|
31.12.2020, 12:28 |
5 |
h6gh, а ты можешь пойти почитать немного, что такое C#, класс и методы класса, а не писать в вопросах всякую фигню? У тебя не ошибка в логике и не какая-то проблема, которую ты не можешь решить, а ты тупо не хочешь разобраться в базовом синтаксисе языка.
0 |
Basically I’ve been trying fix this error for ages so I can actually look at thee game in play mode. It is a script for enemy AI who will chase the player around.
The error is at (90,32) which is attempting to transform the enemys vision when they attack the player
The line that is creating the issue is transform LookAt(player);
Any help would be much appreciated.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
public class EnemyAI : MonoBehaviour
{
public NavMeshAgent agent;
public Transform player;
public LayerMask whatIsGround, whatIsPlayer;
public int Damage = 5;
//Patrolling
public Vector3 walkPoint;
bool walkPointSet;
public float walkPointRange;
//Attacking
public float timeBetweenAttacks;
bool alreadyAttacked;
//States
public float sightRange, attackRange;
public bool playerInSightRange, playerInAttackRange;
private void Awake()
{
player = GameObject.Find("player").transform;
agent = GetComponent<NavMeshAgent>();
}
private void Update()
{
//Check for attack and sight range
playerInSightRange = Physics.CheckSphere(transform.position, sightRange, whatIsPlayer);
playerInAttackRange = Physics.CheckSphere(transform.position, attackRange, whatIsPlayer);
if (!playerInSightRange && !playerInAttackRange) Patrolling();
if (playerInSightRange && !playerInAttackRange) ChasePlayer();
if (playerInSightRange && playerInAttackRange) AttackPlayer();
}
private void Patrolling()
{
if (!walkPointSet) SearchWalkPoint();
if (walkPointSet)
agent.SetDestination(walkPoint);
Vector3 distanceToWalkPoint = transform.position - walkPoint;
//when walkpoint is reached
if (distanceToWalkPoint.magnitude < 1f)
walkPointSet = false;
}
private void SearchWalkPoint()
// Will calculate and random point on the x and z axis
{
float randomZ = Random.Range(-walkPointRange, walkPointRange);
float randomX = Random.Range(-walkPointRange, walkPointRange);
walkPoint = new Vector3(transform.position.x + randomX, transform.position.y, transform.position.z + randomZ);
if (Physics.RayCast(walkPoint, -transform.up, 2f, whatIsGround))
walkPointSet = true;
}
private void ChasePlayer()
{
agent.SetDestination(player.position);
}
private void AttackPlayer()
{
agent.SetDestination(transform.position);
transform LookAt(player);
if (!alreadyAttacked)
{
alreadyAttacked = true;
invoke(nameof(ResetAttack), timeBetweenAttacks);
}
}
private void ResetAttack()
{
alreadyAttacked = false;
}
void OnTriggerEnter(Collider other)
{
Debug.Log("Collison");
if (other.gameObject.tag == "player")
{
if (other.gameObject.GetComponent<Health>() == true)
{
other.gameObject.GetComponent<Health>().TakeDamage(Damage);
}
}
}
}
using System; using UnityEngine; using UnityEngine.UI; namespace UnityStandardAssets.Utility { [RequireComponent(typeof (Text.))] public class FPSCounter : MonoBehaviour { const float fpsMeasurePeriod = 0.5f; private int m_FpsAccumulator = 0; private float m_FpsNextPeriod = 0; private int m_CurrentFps; const string display = "{0} FPS"; private void Start() { m_FpsNextPeriod = Time.realtimeSinceStartup + fpsMeasurePeriod; m_GuiText.text = GetComponent<Text>(); } private void Update() { m_FpsAccumulator++; if (Time.realtimeSinceStartup > m_FpsNextPeriod) { m_CurrentFps = (int) (m_FpsAccumulator/fpsMeasurePeriod); m_FpsAccumulator = 0; m_FpsNextPeriod += fpsMeasurePeriod; m_GuiText.text = string.Format(display, m_CurrentFps); } } } }
What I have tried:
so im pretty new to unity so bear with me please. I downloaded this assets pack from the unity store and created my scene i am getting this error though and have no idea how to fix it. i have spent hours online trying to figure it out but everything i am trying is not working so i would really greatly appreciate some help. thank you so much! I keep on getting this error : Assets/EgyptAssetPack/Standard Assets/Utility/FPSCounter.cs(8,36): error CS1001: Identifier expected
[RequireComponent(typeof (Text.))]
Remove the dot.
Dot in C# is a separator — the system is expecting you to supply a qualified type such as «Text.myclass» which doesn’t exist.
[RequireComponent(typeof (Text))]
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)
CodeProject,
20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8
+1 (416) 849-8900
CS1001 – Identifier expected
Reason for the Error & Solution
Identifier expected
You did not supply an identifier. An identifier is the name of a class, struct, namespace, method, variable, and so on, that you provide.
The following example declares a simple class but does not give the class a name:
public class //CS1001
{
public int Num { get; set; }
void MethodA() {}
}
The following sample generates CS1001 because, when declaring an enum, you must specify members:
public class Program
{
enum Colors
{
'a', 'b' // CS1001, 'a' is not a valid int identifier
// The following line shows examples of valid identifiers:
// Blue, Red, Orange
};
public static void Main()
{
}
}
Parameter names are required even if the compiler doesn’t use them, for example, in an interface definition. These parameters are required so that programmers who are consuming the interface know something about what the parameters mean.
interface IMyTest
{
void TestFunc1(int, int); // CS1001
// Use the following line instead:
// void TestFunc1(int a, int b);
}
class CMyTest : IMyTest
{
void IMyTest.TestFunc1(int a, int b)
{
}
}