UnityEngine.Touch is a type, and you’re trying it to use as if it was a namespace. Well, that’s also what the error says. Just remove that line and you should be fine.
There’s a way you can use a type there, and that’s what the message suggests: “using static” (C# 6+ feature) but it’s definitely not needed here.
error CS0029: Cannot implicitly convert type UnityEngine.Touch' to Touch’
error CS1061: Type Touch' does not contain a definition for position’ and no extension method position' of type Touch’ could be found. Are you missing an assembly reference?
error CS1061: Type Touch' does not contain a definition for phase’ and no extension method phase' of type Touch’ could be found. Are you missing an assembly reference?
It seems you created a type with name “Touch” in your project, which is - just like your current type DragControll - declared in the global namespace (the default namespace, or “no explicit” namespace). You might as well have imported a plugin or other assets, but good plugins usually come with their own namespaces, so I guess it’s just somewhere in your project.
The compiler thinks you want to use that “Touch” in line 21 of your script, rather than UnityEngine.Touch, so the compiler sees that line as trying to treat an apple (a “UnityEngine.Touch”) like an orange (a “Touch”).
If you’re using Visual Studio, click on that “Touch” and hit F12. It’ll jump to the definition of that type. Other IDEs should have a similar “go to defintiion” functionality.
Hm yes, that’s what you could do - but it only solves the problem in this specific case, and doesn’t really fix that annoying issue once and forever.
The replacement would just be “Touch” => “UnityEngine.Touch” in order to be more explicit, so that the compiler knows that you actually want the engine’s touch type. The shorter version is based on type inference, which is just a simple “var”.
UnityEngine.Touch touch = ...
// or shorter, allowing to infer the type from the expression on the right side of the assignement operator
var touch = ...
What you should do:
Find that type named “Touch” in your project, and either remove it (if no longer needed), or rename it (if still needed). It’s generally a good practice to avoid type names that are already used in Unity (this does actually apply to every environment, doesn’t need to be Unity), or at least to wrap your own definitions in your own namespace (it’s always a good idea to use namespace, you’ll immediately know whether some type is yours, or comes from a different source and it helps to organize all your own types).
Sorry for bothering, I’m still learning to work in Unity and VisualStudio. I replaced “Touch” with “var” , but I still get errors, 4 of them. I feel like I should declare a variable on line 11, but what.
error CS1061: Type UnityEngine.Vector2' does not contain a definition for z’ and no extension method z' of type UnityEngine.Vector2’ could be found. Are you missing an assembly reference?
error CS0103: The name `delataX’ does not exist in the current context
error CS1061: Type UnityEngine.Vector2' does not contain a definition for z’ and no extension method z' of type UnityEngine.Vector2’ could be found. Are you missing an assembly reference?
error CS1729: The type UnityEngine.Vector2' does not contain a constructor that takes 3’ arguments
Yes, these errors are different ones, and they’re now considered unrelated to the previous errors, hence they do pop-up now.
A Vector2 has only two dimensions, hence the 2 as appendix, ‘z’ being none of them (in Unity). A three-dimensional vector has x, y, z components.
If you intended to use ‘z’, i.e. three dimensions, which you did apparently, at least that’s what the whole code snippet suggests, you should replace Vector2 with Vector3. That should solve these errors.
This one’s just popping up due to your typo. You’ve got a variable with the identifier “deltaX”, but you’ve typed “delataX”.
im using the random audio player script from unity 2d plateformer kit
and im using sprites and the code hsa a reference to tilemaps.
so i use " Public Sprite PlateformObject;" and i get errors
about not having using static and when i use the using static unityengine.sprite; i get the error that this isnt supported in c# 4 . please help
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using static UnityEngine.Sprite;
namespace Gamekit2D
{
[RequireComponent(typeof(AudioSource))]
public class RandomAudioPlayer : MonoBehaviour
{
[System.Serializable]
public struct TileOverride
{
//public TileBase tile;
public Sprite PlateformObject;
public AudioClip[ ] clips;
}
public AudioClip[ ] clips;
public Sprite[ ] overrides;
public bool randomizePitch = false;
public float pitchRange = 0.2f;