質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.47%
Unity

Unityは、Unity Technologiesが開発・販売している、IDEを内蔵するゲームエンジンです。主にC#を用いたプログラミングでコンテンツの開発が可能です。

Q&A

解決済

1回答

1646閲覧

Joystickエラーが出る

退会済みユーザー

退会済みユーザー

総合スコア0

Unity

Unityは、Unity Technologiesが開発・販売している、IDEを内蔵するゲームエンジンです。主にC#を用いたプログラミングでコンテンツの開発が可能です。

1グッド

1クリップ

投稿2020/03/14 16:48

現状

前回使っていた時には使用できたのにaseetをインポートした瞬間からエラーになってしまっている

エラー文

Assets/Joystick Pack/Scripts/Base/Joystick.cs(69,19): error CS0029: Cannot implicitly convert type 'UnityEngine.Camera' to 'Camera'
Assets/Joystick Pack/Scripts/Base/Joystick.cs(71,68): error CS1503: Argument 1: cannot convert from 'Camera' to 'UnityEngine.Camera'

unityengine.cameraを暗黙的に変換できません

試したこと

プロジェクト新しいのを作ってインポート
アッセットのdemoも再生できない

該当スクリプト

unity

1using System.Collections; 2using System.Collections.Generic; 3using UnityEngine; 4using UnityEngine.EventSystems; 5 6public class Joystick : MonoBehaviour, IPointerDownHandler, IDragHandler, IPointerUpHandler 7{ 8 public float Horizontal { get { return (snapX) ? SnapFloat(input.x, AxisOptions.Horizontal) : input.x; } } 9 public float Vertical { get { return (snapY) ? SnapFloat(input.y, AxisOptions.Vertical) : input.y; } } 10 public Vector2 Direction { get { return new Vector2(Horizontal, Vertical); } } 11 12 public float HandleRange 13 { 14 get { return handleRange; } 15 set { handleRange = Mathf.Abs(value); } 16 } 17 18 public float DeadZone 19 { 20 get { return deadZone; } 21 set { deadZone = Mathf.Abs(value); } 22 } 23 24 public AxisOptions AxisOptions { get { return AxisOptions; } set { axisOptions = value; } } 25 public bool SnapX { get { return snapX; } set { snapX = value; } } 26 public bool SnapY { get { return snapY; } set { snapY = value; } } 27 28 [SerializeField] private float handleRange = 1; 29 [SerializeField] private float deadZone = 0; 30 [SerializeField] private AxisOptions axisOptions = AxisOptions.Both; 31 [SerializeField] private bool snapX = false; 32 [SerializeField] private bool snapY = false; 33 34 [SerializeField] protected RectTransform background = null; 35 [SerializeField] private RectTransform handle = null; 36 private RectTransform baseRect = null; 37 38 private Canvas canvas; 39 private Camera cam; 40 41 private Vector2 input = Vector2.zero; 42 43 protected virtual void Start() 44 { 45 HandleRange = handleRange; 46 DeadZone = deadZone; 47 baseRect = GetComponent<RectTransform>(); 48 canvas = GetComponentInParent<Canvas>(); 49 if (canvas == null) 50 Debug.LogError("The Joystick is not placed inside a canvas"); 51 52 Vector2 center = new Vector2(0.5f, 0.5f); 53 background.pivot = center; 54 handle.anchorMin = center; 55 handle.anchorMax = center; 56 handle.pivot = center; 57 handle.anchoredPosition = Vector2.zero; 58 } 59 60 public virtual void OnPointerDown(PointerEventData eventData) 61 { 62 OnDrag(eventData); 63 } 64 65 public void OnDrag(PointerEventData eventData) 66 { 67 cam = null; 68/////////////////////該当場所////////////////////////////// 69 if (canvas.renderMode == RenderMode.ScreenSpaceCamera) 70 cam = canvas.worldCamera; 71///////////////////////////////////////////////////////////////// 72 Vector2 position = RectTransformUtility.WorldToScreenPoint(cam, background.position); 73 Vector2 radius = background.sizeDelta / 2; 74 input = (eventData.position - position) / (radius * canvas.scaleFactor); 75 FormatInput(); 76 HandleInput(input.magnitude, input.normalized, radius, cam); 77 handle.anchoredPosition = input * radius * handleRange; 78 } 79 80 protected virtual void HandleInput(float magnitude, Vector2 normalised, Vector2 radius, Camera cam) 81 { 82 if (magnitude > deadZone) 83 { 84 if (magnitude > 1) 85 input = normalised; 86 } 87 else 88 input = Vector2.zero; 89 } 90 91 private void FormatInput() 92 { 93 if (axisOptions == AxisOptions.Horizontal) 94 input = new Vector2(input.x, 0f); 95 else if (axisOptions == AxisOptions.Vertical) 96 input = new Vector2(0f, input.y); 97 } 98 99 private float SnapFloat(float value, AxisOptions snapAxis) 100 { 101 if (value == 0) 102 return value; 103 104 if (axisOptions == AxisOptions.Both) 105 { 106 float angle = Vector2.Angle(input, Vector2.up); 107 if (snapAxis == AxisOptions.Horizontal) 108 { 109 if (angle < 22.5f || angle > 157.5f) 110 return 0; 111 else 112 return (value > 0) ? 1 : -1; 113 } 114 else if (snapAxis == AxisOptions.Vertical) 115 { 116 if (angle > 67.5f && angle < 112.5f) 117 return 0; 118 else 119 return (value > 0) ? 1 : -1; 120 } 121 return value; 122 } 123 else 124 { 125 if (value > 0) 126 return 1; 127 if (value < 0) 128 return -1; 129 } 130 return 0; 131 } 132 133 public virtual void OnPointerUp(PointerEventData eventData) 134 { 135 input = Vector2.zero; 136 handle.anchoredPosition = Vector2.zero; 137 } 138 139 protected Vector2 ScreenPointToAnchoredPosition(Vector2 screenPosition) 140 { 141 Vector2 localPoint = Vector2.zero; 142 if (RectTransformUtility.ScreenPointToLocalPointInRectangle(baseRect, screenPosition, cam, out localPoint)) 143 { 144 Vector2 pivotOffset = baseRect.pivot * baseRect.sizeDelta; 145 return localPoint - (background.anchorMax * baseRect.sizeDelta) + pivotOffset; 146 } 147 return Vector2.zero; 148 } 149} 150 151public enum AxisOptions { Both, Horizontal, Vertical }
s.k👍を押しています

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

Camera というクラスを作っていませんか?

どうしてもうまくいかないなら、下記のようにしてみてください

private UnityEngine.Camera cam;

投稿2020/03/14 18:31

izmktr

総合スコア2856

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.47%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問