using UnityEngine;
using System.Collections;
public class Sword : MonoBehaviour {
var totalhealth = 100;
function OnTriggerEnter(other : Collider){
if(other.tag == "angelic_sword_02"){
totalhealth -= 50;
}
}
function Update(){
if(totalhealth <= 0){
Destroy(gameObject);
}
}
}
I get an «Identifier Expected» in the script where it says in the line
function OnTriggerEnter(other : Collider) {
Any help please?
marc_s
728k174 gold badges1326 silver badges1455 bronze badges
asked May 8, 2015 at 1:14
5
You are using incorrect syntax for a C# method. Unity supports multiple languages for user code. Perhaps you copied an example from a different language?
function OnTriggerEnter(other : Collider){
if(other.tag == "angelic_sword_02"){
totalhealth -= 50;
}
}
Should be closer to
public void OnTriggerEnter(Collider other){
if(other.tag == "angelic_sword_02"){
totalhealth -= 50;
}
}
answered May 8, 2015 at 1:19
Eric J.Eric J.
147k63 gold badges339 silver badges552 bronze badges
2
I finally figured it out. And I have no more compiler errors anymore.
using UnityEngine;
using System.Collections;
public class Sword : MonoBehaviour {
public float totalhealth = 100;
public void OnTriggerEnter(Collider other){
if(other.tag == "angelic_sword_02"){
totalhealth -= 50;
}
}
void Update(){
if(totalhealth <= 0){
Destroy(gameObject);
}
}
}
@EricJ thank you for helping me out. 
answered May 8, 2015 at 1:39
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlaerMufment : MonoBehaviour {
CharacterController cc;
Vector3 moveVec;
float speed = 5;
int laneNamber = 1,
lanesCount = 2;
public float FirstlanePos,
LaneDistance,
SideSpeed;
void Start()
{
cc = GetComponent<CharacterController>();
moveVec = new Vector3(1, 0, 0);
}
void Update()
{
moveVec.x *= speed;
moveVec *= Time.deltaTime;
float imput = Input.GetAxis("Horizontal");
if (Mathf.Abs(input) >.if);
{
laneNamber += (int)Matht.Sign(input);
laneNamber = Mathf.Clamp(laneNamber, 0, lanesCount);
}
Vectore3 newPos = transfore.position;
newPos.z = Mathf.Lerp(newPos.z, FirstLanePos + (laneNamber * LaneDistance), Time.deltaTime * SideSpeed);
transform.position = newPos;
cc.Move(moveVec);
}
}
AssetsSkriptPlaerMufment.cs(36,31): error CS1525: Invalid expression term ‘.’
AssetsSkriptPlaerMufment.cs(36,32): error CS1001: Identifier expected
AssetsSkriptPlaerMufment.cs(36,32): error CS1026: ) expected
AssetsSkriptPlaerMufment.cs(36,34): error CS1003: Syntax error, ‘(‘ expected
AssetsSkriptPlaerMufment.cs(36,34): error CS1525: Invalid expression term ‘)’
Go to unity
r/unity
Unity is the ultimate game development platform. Use Unity to build high-quality 3D and 2D games, deploy them across mobile, desktop, VR/AR, consoles or the Web, and connect with loyal and enthusiastic players and customers.
This community is being built to help users of all levels gain access to resources, information, and support from other users in regards to anything Unity. You can showcase your work and use this forum to connect with others sharing the same passions.
Post away!
Members
Online
•
error CS1001: Identifier expected
im trying to make an object spawn at certain coordinates, but when i put in the script this is what it says: Assetsdrop.cs(5,31): error CS1001: Identifier expected
my code:
using UnityEngine;
public class InstantiationExample : MonoBehaviour
{
public GameObject (myPrefab);
void Start()
{
Instantiate(myPrefab, new Vector3(0, 0, 0), Quaternion.identity);
}
}
can someone help me? im very new to c# and unity.
Перейти к контенту
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)
{
}
}
First off, indent your code properly:
using System.Collections; using System.Collections.Generic; using UnityEngine; public class Paddle : MonoBehaviour { public bool isPlayer1; public float speed; public rigidbody2D rb; private float movement; void Update() { { if (isPlayer1) { movement = Input.GetAxisRaw("Vertical"); } } movement = Input.GetAxisRaw("Vertical2"); } rb.velocity = new Vector2(rb.velocity.x, movement * speed); }
It makes it a lot clearer to see what is actually happening!
And the first thing that is obvious is that there is a pair of redundant curly brackets in there:
void Update() { if (isPlayer1) { movement = Input.GetAxisRaw("Vertical"); } movement = Input.GetAxisRaw("Vertical2"); }
The second thing that becomes obvious is that this line of code:
rb.velocity = new Vector2(rb.velocity.x, movement * speed);
Isn’t inside any method.
That won’t compile: you cannot execute code unless it is inside a method — there is no way to call it!
So start out by working out where that code should be, and your problems may start to go away…
