Mail.ruПочтаМой МирОдноклассникиВКонтактеИгрыЗнакомстваНовостиКалендарьОблакоЗаметкиВсе проекты

Ошибки в Unity 3D.

Константин Ермаков Ученик (150), закрыт 3 месяца назад
Я делал управление свайпами для казуалки на Unity, и мне вылезло целых 5 ошибок, вот код:
using UnityEngine;

public class SwipeDetector : MonoBehaviour
{
public static event OnSwipeInput SwipeEvent;
public delegate void OnSwipeInput(Vector2 Direction);

private Vector2 tapPosition;
private Vector2 swipeDelta;

private float deadZone = 80;

private bool isSwiping;
private bool isMobile;

void start()
{
isMobile = application.isMobilePlatform;
}

void update()
{
if(!isMobile)
{
if (input.GetMouseButtonDown(0))
{
isSwiping = True;
tapPosition = input.mousePosition;
}

else if (input.GetMouseButtonUp(0))
ResetSwipe();
}
else
{
if (input.touchCount > 0)
{
if (input.GetTouch(0).phase == TouchPhase.Began)
{
isSwiping = True;
tapPosition = input.GetTouch(0).position;
}
else if (input.GetTouch(0).phase == TouchPhase.Canceled||
input.GetTouch(0).phase == TouchPhase.Ended)
{
ResetSwipe
}
}
}
ChekSwipe();
}

private void ChekSwipe()
{
swipeDelta = Vector2.zero ;

if (isSwiping)
{
if (!isMobile && input.GetMouseButton(0))
swipeDelta = (Vector2)input.mousePosition - tapPosition;
else if (input.touchCount > 0)
swipeDelta = input.GetTouch(0).position - tapPosition;
}

if (swipeDelta.magnitude > deadZone)
{
if (SwipeEvent != null)
{
if (mathf.Abs(swipeDelta.x) > mathf.Abs(swipeDelta.y))
SwipeEvent(swipeDelta.x > 0 ? Vector2.Right : Vector2.left);
else
SwipeEvent (swipeDelta.y > 0 ? Vector2.up : Vector2.down);
}

ResetSwipe();
}
}

private void ResetSwipe()
{
isSwiping = false;

tapPosition = Vector2.zero ;
swipeDelta = Vector2.zero ;
}
}
остальное добавлю в дополнении, помогите пожалуйста исправить их
Дополнен 3 месяца назад
2 cкрипт: using UnityEngine;
using UnityEngine.SceneManagement;

public class Player : MonoBehaviour
{
[SerializeField] KeyCode KeyOne;
[SerializeField] KeyCode KeyTwo;
[SerializeField] Vector3 moveDirection;

private void FixedUpdate()
{
if(Input.GetKey(KeyOne))
{
GetComponent<Rigidbody>().linearVelocity += moveDirection;
}
if(Input.GetKey(KeyTwo))
{
GetComponent<Rigidbody>().linearVelocity -= moveDirection;
}
if(Input.GetKey(KeyCode.R))
{
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
}

SwipeDetector.SwipeEvent += OnSwipe;
}

private void OnSwipe(Vector2 Direction)
{
Vector3 dir = Direction == Vector2.up ? Vector3.forward :
Direction == Vector2.down ? Vector3.back : (Vector3)Direction;

Move(dir);
}

private void OnTriggerEnter(Collider other)
{
if(this.CompareTag("Player") && other.CompareTag("Finish"))
{
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1);
}
}
}
Дополнен 3 месяца назад
2 ошибка:
Failed to find entry-points:
Mono.Cecil.AssemblyResolutionException: Failed to resolve assembly: 'Assembly-CSharp-Editor, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' ---> System.Exception: Failed to resolve assembly 'Assembly-CSharp-Editor, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' in directories: C:\Program Files\Unity\Hub\Editor\6000.0.25f1\Editor\Data\MonoBleedingEdge\lib\mono\unityjit-win32
C:\Program Files\Unity\Hub\Editor\6000.0.25f1\Editor\Data\MonoBleedingEdge\lib\mono\unityjit-win32\Facades
D:\юнити проекты\3D Casual Puzzle Game\Library\PackageCache\com.unity.visualscripting\Editor\VisualScripting.Core\Dependencies\DotNetZip
D:\юнити проекты\3D Casual Puzzle Game\Library\PackageCache\com.unity.collab-proxy\Lib\Editor
C:\Program Files\Unity\Hub\Editor\6000.0.25f1\Editor\Data\Managed
D:\юнити проекты\3D Casual Puzzle Game\Library\PackageCache\com.unity.visualscripting\Editor\VisualScripting.Core\EditorAssetResources
D:\юнити проекты\3D Casual Puzzle Game\Library\PackageCache\com.unity.ide.rider\Rider\Editor
D:\юнити проекты\3D Casual Puzzle Game\Library\PackageCache\com.unity.nuget.newtonsoft-json\Runtime
D:\юнити проекты\3D Casual Puzzle Game\Library\PackageCache\com.unity.burst
D:\юнити проекты\3D Casual Puzzle Game\Library\PackageCache\com.unity.burst\Unity.Burst.CodeGen
C:\Program Files\Unity\Hub\Editor\6000.0.25f1\Editor\Data\PlaybackEngines\WindowsStandaloneSupport
C:\Program Files\Unity\Hub\Editor\6000.0.25f1\Editor\Data\PlaybackEngines\WebGLSupport
D:\юнити проекты\3D Casual Puzzle Game\Library\PackageCache\com.unity.ext.nunit\net40\unity-custom
D:\юнити проекты\3D Casual Puzzle Game\Library\PackageCache\com.unity.nuget.mono-cecil
Дополнен 3 месяца назад
D:\юнити проекты\3D Casual Puzzle Game\Library\PackageCache\com.unity.visualscripting\Editor\VisualScripting.Core\Dependencies\YamlDotNet

D:\юнити проекты\3D Casual Puzzle Game\Library\PackageCache\com.unity.nuget.newtonsoft-json\Runtime\AOT

D:\юнити проекты\3D Casual Puzzle Game\Library\PackageCache\com.unity.collections\Unity.Collections.LowLevel.ILSupport

D:\юнити проекты\3D Casual Puzzle Game\Library\PackageCache\com.unity.visualscripting\Runtime\VisualScripting.Flow\Dependencies\NCalc

C:\Program Files\Unity\Hub\Editor\6000.0.25f1\Editor\Data\Managed\UnityEngine

C:\Program Files\Unity\Hub\Editor\6000.0.25f1\Editor\Data\PlaybackEngines\WebGLSupport\Managed

D:\юнити проекты\3D Casual Puzzle Game\Library\ScriptAssemblies ---> Mono.Cecil.AssemblyResolutionException: Failed to resolve assembly: 'Assembly-CSharp-Editor, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'

at Mono.Cecil.BaseAssemblyResolver.Resolve (Mono.Cecil.AssemblyNameReference name, Mono.Cecil.ReaderParameters parameters) [0x00105] in <853812ae52c341daaef3c62ecdb86b32>:0

at zzzUnity.Burst.CodeGen.AssemblyResolver.Resolve (Mono.Cecil.AssemblyNameReference name) [0x00007] in <69b504cf34c54d688310e60f1ce29d2e>:0

--- End of inner exception stack trace ---

at zzzUnity.Burst.CodeGen.AssemblyResolver.Resolve (Mono.Cecil.AssemblyNameReference name) [0x00054] in <69b504cf34c54d688310e60f1ce29d2e>:0

at Burst.Compiler.IL.AssemblyLoader.Resolve (Mono.Cecil.AssemblyNameReference name) [0x0007e] in <69b504cf34c54d688310e60f1ce29d2e>:0

at Burst.Compiler.IL.Server.EntryPointMethodFinder.FindEntryPoints (System.String[] rootAssemblyNames,
Дополнен 3 месяца назад
Burst.Compiler.IL.Hashing.CacheRuntime.HashCacheAssemblyStore assemblyStore, Burst.Compiler.IL.AssemblyLoader assemblyLoader, Burst.Compiler.IL.NativeCompilerOptions options, Burst.Compiler.IL.Server.ProfileDelegate profileCallback, System.Boolean includeRootAssemblyReferences, System.Boolean splitTargets) [0x00055] in <69b504cf34c54d688310e60f1ce29d2e>:0



at Burst.Compiler.IL.Server.CompilerServer+<>c__DisplayClass18_1.<FindMethods>b__0 (Burst.Compiler.IL.Server.Caching.CacheManager cacheManager) [0x0005e] in <69b504cf34c54d688310e60f1ce29d2e>:0



at Burst.Compiler.IL.Server.CompilerServer+<>c__DisplayClass26_0`1[TResult].<RunTask>b__0 () [0x00145] in <69b504cf34c54d688310e60f1ce29d2e>:0



at Burst.Compiler.IL.Server.CompilerServer.RunTask[TResult] (Burst.Compiler.IL.Server.TargetKey target, System.String taskName, System.String[] assemblyFolders, System.Threading.CancellationToken cancellationToken, System.Func`2[T,TResult] function) [0x00131] in <69b504cf34c54d688310e60f1ce29d2e>:0



at Burst.Compiler.IL.Server.CompilerServer.FindMethods (Burst.Compiler.IL.Server.CompilerServerOptions options, Burst.Compiler.IL.Aot.AotCompilerOptions aotOptions, Burst.Compiler.IL.AssemblyDefinesDict assemblyDefines, Burst.Compiler.IL.Server.TargetKey target, Burst.Compiler.IL.Server.Caching.CacheManager cacheManager, Burst.Compiler.IL.CompilerStatistics stats, System.Threading.CancellationToken cancellationToken) [0x00299] in <69b504cf34c54d688310e60f1ce29d2e>:0



at Burst.Compiler.IL.Server.CompilerServer+<>c__DisplayClass26_0`1[TResult].<RunTask>b__0 () [0x00145] in <69b504cf34c54d688310e60f1ce29d2e>:0
Дополнен 3 месяца назад
at Burst.Compiler.IL.Server.CompilerServer.RunTask[TResult] (Burst.Compiler.IL.Server.TargetKey target, System.String taskName, System.String[] assemblyFolders, System.Threading.CancellationToken cancellationToken, System.Func`2[T,TResult] function) [0x00131] in <69b504cf34c54d688310e60f1ce29d2e>:0







at Burst.Compiler.IL.Server.CompilerServer.Compile (Burst.Compiler.IL.Server.CompilerServerOptions options, Burst.Compiler.IL.Server.CompilationMessageStreamer streamer, System.Threading.CancellationToken cancellationToken) [0x001ca] in <69b504cf34c54d688310e60f1ce29d2e>:0



While compiling job:
Дополнен 3 месяца назад
1 ошибка:
Assets\TutorialInfo\Scripts\SwipeDetector.cs(46,31): error CS1002: ; expected
2, 3, 4 и 5 ошибки абсолютно одинаковые
Лучший ответ
S.H.I. Оракул (73933) 3 месяца назад
Исправленный код SwipeDetector.cs:
 using UnityEngine;   

public class SwipeDetector : MonoBehaviour
{
public static event OnSwipeInput SwipeEvent;
public delegate void OnSwipeInput(Vector2 Direction);

private Vector2 tapPosition;
private Vector2 swipeDelta;

private float deadZone = 80;

private bool isSwiping;
private bool isMobile;

void Start() // Заглавная S
{
isMobile = Application.isMobilePlatform; // Заглавная A
}

void Update() // Заглавная U
{
if (!isMobile)
{
if (Input.GetMouseButtonDown(0)) // Заглавная I
{
isSwiping = true; // строчная t
tapPosition = Input.mousePosition;
}
else if (Input.GetMouseButtonUp(0))
ResetSwipe();
}
else
{
if (Input.touchCount > 0)
{
if (Input.GetTouch(0).phase == TouchPhase.Began)
{
isSwiping = true;
tapPosition = Input.GetTouch(0).position;
}
else if (Input.GetTouch(0).phase == TouchPhase.Canceled ||
Input.GetTouch(0).phase == TouchPhase.Ended)
{
ResetSwipe(); // Добавлены () и ;
}
}
}
CheckSwipe(); // Исправлено название метода
}

private void CheckSwipe() // Правильное название
{
swipeDelta = Vector2.zero;

if (isSwiping)
{
if (!isMobile && Input.GetMouseButton(0))
swipeDelta = (Vector2)Input.mousePosition - tapPosition;
else if (Input.touchCount > 0)
swipeDelta = Input.GetTouch(0).position - tapPosition;
}

if (swipeDelta.magnitude > deadZone)
{
SwipeEvent?.Invoke( // Упрощено с использованием null-conditional
Mathf.Abs(swipeDelta.x) > Mathf.Abs(swipeDelta.y) // Заглавная M
? (swipeDelta.x > 0 ? Vector2.right : Vector2.left)
: (swipeDelta.y > 0 ? Vector2.up : Vector2.down)
);
ResetSwipe();
}
}

private void ResetSwipe()
{
isSwiping = false;
tapPosition = Vector2.zero;
swipeDelta = Vector2.zero;
}
}
S.H.I.Оракул (73933) 3 месяца назад
Исправленный код Player.cs: https://pastebin.com/xSN2j2kP
Константин ЕрмаковУченик (150) 3 месяца назад
А как можно в скрипте SwipeDetector.cs ускорить движение игрока?
Остальные ответы
Макар Новиков Гуру (2617) 3 месяца назад
А ошибки прикрепить? Или я должен твой немаркированый код час читать?
Константин ЕрмаковУченик (150) 3 месяца назад
я их прикреплял в дополнении, там максимальный объем вопроса не резиновый
Гайковёрт Профи (793) 3 месяца назад
В вашем коде есть несколько проблем, которые могут вызывать ошибки. Вот исправления и объяснения для каждой из них:

1. Ошибки в именах методов и классов

start() и update() должны быть с заглавной буквы: Start() и Update().

application.isMobilePlatform должно быть Application.isMobilePlatform.

input.GetMouseButtonDown(0) и т.д. должно быть Input.GetMouseButtonDown(0) и т.д.

mathf.Abs() и другие вызовы методов из класса Mathf должны быть Mathf.Abs().


Исправление:

void Start()
{
isMobile = Application.isMobilePlatform;
}

void Update()
{
if (!isMobile)
{
if (Input.GetMouseButtonDown(0))
{
isSwiping = true;
tapPosition = Input.mousePosition;
}
else if (Input.GetMouseButtonUp(0))
{
ResetSwipe();
}
}
else
{
if (Input.touchCount > 0)
{
if (Input.GetTouch(0).phase == TouchPhase.Began)
{
isSwiping = true;
tapPosition = Input.GetTouch(0).position;
}
else if (Input.GetTouch(0).phase == TouchPhase.Canceled || Input.GetTouch(0).phase == TouchPhase.Ended)
{
ResetSwipe();
}
}
}
ChekSwipe();
}


---

2. Ошибка в использовании события

Вы объявили событие public static event OnSwipeInput SwipeEvent;, но перед ним должна быть корректно объявлена делегат-функция.

Исправление:

public delegate void OnSwipeInput(Vector2 direction);
public static event OnSwipeInput SwipeEvent;


---

3. Опечатка в ResetSwipe()

В коде отсутствует вызов метода ResetSwipe() (скобки забыты). Нужно добавить скобки ().

Исправление:

ResetSwipe();


---

4. Ошибка с Vector2.Right

В Unity нет свойства Vector2.Right, нужно заменить на Vector2.right.

Исправление:

SwipeEvent(swipeDelta.x > 0 ? Vector2.right : Vector2.left);


---

5. Опечатки в других местах

ChekSwipe должно быть CheckSwipe.

True должно быть true.
Константин ЕрмаковУченик (150) 3 месяца назад
Я сделал так, как вы написали, но появилась еще одна ошибка:

Assets\TutorialInfo\Scripts\Player.cs(33,9): error CS0103: The name 'Move' does not exist in the current context
как ее исправить?
Похожие вопросы