Click here to Skip to main content
15,881,803 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I had made a C# script in unity about dashing my character here is the script .
public class Dash : MonoBehaviour
{
Movement Move;
public float DashSpeed;
private float DashTime;

// Start is called before the first frame update
void Start()
{
Move=GetComponent<movement>();
}

// Update is called once per frame
void Update()
{
if(Input.GetKey(KeyCode.LeftShift)||Input.GetKey(KeyCode.RightShift))
{
StartCoroutine(Dashing());

}
}
IEnumerator Dashing()
{
float startTime= Time.time;

while(Time.time < startTime + DashTime)
{
Move.Movement.Move(Move.runSpeed * DashSpeed *Time.deltaTime);

yield return null;
}

What I have tried:

Actually I did take a bit help from tutorials but not copy pasting entire code.Previosly my script had class name and method name same I changed that and I had another bug due to writting Move.controller.move();. since I didn't had character controller like tutorial nor I can add Character controller script I had due to console error so I changed to Move.controller.move(); to Move.Movement.move(); and I came up this error as mentioned above look at script where the error is
IEnumerator Dashing()
{
float startTime= Time.time;

while(Time.time < startTime + DashTime)
{
Move.Movement.Move(Move.runSpeed * DashSpeed *Time.deltaTime);

yield return null;
}
Posted
Updated 22-Dec-21 19:55pm

1 solution

First off, C# is case sensitive: so Movement is not the same as movement.
You first example code uses both, so one of them will be wrong:
Movement Move;
...
void Start()
   {
   Move=GetComponent<movement>();
   }


The second example tells the system that the Movement class contains a property called Movement:
Move.Movement.Move(Move.runSpeed * DashSpeed *Time.deltaTime);
And that isn't the case - which is why you get the error.

And both of those tell me the same thing: you don't know what you are doing, and instead of learning how to do things you are watching half-assed "youtube tutorials" and guessing.
That will not work. You need to learn the basics of C# properly first and ignore everything on YouTube as it's pretty much all rubbish produced just for likes and subscribes. Go on a course, get a book: and do all the exercises - there is no short cut to this!
 
Share this answer
 
Comments
Ninja Boy 25-Dec-21 6:13am    
Well it's not that I don't know anything it that I don't have enough practice and this is my 1st time doing it on my own and I am not entirely new to c# I know how to make if statements(not entirely on my own taking bits and pieces of different code and modifying it but not knowing how to modify it .After Reading your comment I think I need a lot of practice. )

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