C#
1using System.Collections; 2using System.Collections.Generic; 3using UnityEngine; 4 5public class camerascript : MonoBehaviour { 6 7 public GameObject Player; 8 GameObject empty; 9 float x = 1; 10 float y = 1; 11 12 // Use this for initialization 13 void Start () { 14 empty = GameObject.Find("Board"); 15 } 16 17 // Update is called once per frame 18 void Update () { 19 float scroll = Input.GetAxis("Mouse ScrollWheel"); 20 Transform empTra = empty.transform; 21 empTra.localScale = new Vector3(x, y, 0); 22 if(scroll > 0) 23 { 24 x += 0.02f; 25 y += 0.02f; 26 } 27 if(scroll < 0) 28 { 29 x -= 0.02f; 30 y -= 0.02f; 31 } 32 transform.position = new Vector3(Player.transform.position.x, Player.transform.position.y, -10); 33 } 34} 35
GameObjectのBoardは生成されたオブジェクトで、スクリプトでは、このオブジェクトのScaleを操作して、拡大、縮小しています。カメラを動かして拡大縮小する方法も考えましたが、平面のUnity2Dなので、上手くいきませんでした。
上記のスクリプトを使うと、一応は出来るのですが、Boardの位置を原点として拡大縮小されるので、理想としているマウスポインタの位置を中心に拡大縮小するのとは違った形になりました。
マウスポインタの位置を中心として、Scaleを調整する方法を教えていただきたいです。他にもっと良い方法があるのなら、それも教えていただけると幸いです。
回答お願いします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。