• 締切済み

Unity について

Unityでゲームを作っているのですがどうしてもできない部分があり困っています それは 転がる玉にあわせてカメラが動かないのです 転がる玉を作るとカメラが追跡しなく 玉を追ってカメラが追跡するようにすると球が転がりません 理想は転がる玉を一定の距離を保ったまま追跡することなのですが ぜんぜんうまくいかないのです --玉は転がるがカメラが追跡しない方 using UnityEngine; using System.Collections; public class PlayerBehaviour : MonoBehaviour { private void OnCollisionEnter(Collision collision) { Debug.Log("kabe hito"); } public float jumpForce = 10; public float Up = 10; public float Down = 10; public float Right = 10;     public float Left = 10; // Use this for initialization void Start () { } // Update is called once per frame void Update () { if(Input.GetKeyDown(KeyCode.Space)) {      rigidbody.AddForce(0,jumpForce,0); Debug.Log("jump! force=" + jumpForce ); } if(Input.GetKey(KeyCode.UpArrow)) { rigidbody.AddForce(0,0,-Up); Debug.Log("UP force=" + Up ); } if(Input.GetKey(KeyCode.DownArrow)) {      rigidbody.AddForce(0,0,Down); Debug.Log("Down force=" + Down ); } if(Input.GetKey(KeyCode.RightArrow)) { rigidbody.AddForce(-Right,0,0); Debug.Log("Right force=" + Right ); } if(Input.GetKey(KeyCode.LeftArrow)) { rigidbody.AddForce(Left,0,0); Debug.Log("Left force=" + Left ); } } } ------カメラが追跡するが玉は移動するが転がらない方 玉にComponent→Character→Platform Input Controllerを選択 そして玉にJavascriptのThirdPersonCamera 1を入れる ThirdPersonCamera 1の中身は http://forum.unity3d.com/threads/70148-Rotation-around-character-by-pressing-RIGHT-MOUSE-BUTTON のThirdPersonControllerの部分をCharacterControllerに変えたやつ 長くなってしまいましたがほんとに困ってます 助けてください

みんなの回答

  • wingstar
  • ベストアンサー率37% (102/275)
回答No.1

Unityって http://sourceforge.jp/projects/sfnet_unity-linux/ これのことじゃないのですよね? だったら、カテゴリー間違ってんじゃない? ここで、そのUnityのこと聞いてもわかんないよ。 カテゴリー間違えると、こういうことになるという一例ですね。

関連するQ&A

  • unity fの意味

    unityでこういうスクリプトを書きました。 ~~~~~~ using UnityEngine; using System.Collections; public class IfStatements : MonoBehaviour { float coffeeTemperature = 85.0f; float hotLimitTemperature = 70.0f; float coldLimitTemperature = 40.0f; void Update () { if(Input.GetKeyDown(KeyCode.Space)) TemperatureTest(); coffeeTemperature -= Time.deltaTime * 5f; } void TemperatureTest () { // If the coffee's temperature is greater than the hottest drinking temperature... if(coffeeTemperature > hotLimitTemperature) { // ... do this. print("Coffee is too hot."); } // If it isn't, but the coffee temperature is less than the coldest drinking temperature... else if(coffeeTemperature < coldLimitTemperature) { // ... do this. print("Coffee is too cold."); } // If it is neither of those then... else { // ... do this. print("Coffee is just right."); } } } ~~~~~~~~~ ですが、Consoleには冷たいコーヒーしか出て来ません。 float coffeeTemperature = 85.0f; float hotLimitTemperature = 70.0f; float coldLimitTemperature = 40.0f; これってどういう意味なのでしょうか? 85.0f;って? 回答お願いします。

  • Processingでのキーの同時入力

    Processingでゲームを作ろうとしているのですがキーボードの同時入力がうまくいきません。 例えば下記のようなキー入力に応じて黒い四角が動くプログラムを実行しました。方向キーを一つだけ押したときはサクサク動いてくれるのですが、→と↓を同時に押しても斜めに進んでくれません。また、→と←を押した場合もどちらか片方の方に動いてしまいます。 このような問題を解決したいので、Processingでキーボードの同時入力を判定するにはどのようにすればいいのか教えてください。 float x, y; void setup(){ size(400, 400); noStroke(); smooth(); } void draw() { background(255,255,255); fill(0,0,0); rect(x,y,20, 20); if (keyPressed && key == CODED){ if (keyCode == LEFT){ x -= 2; } if (keyCode == RIGHT){ x += 2; } if (keyCode == UP){ y -= 2; } if (keyCode == DOWN){ y += 2; } } }

  • Unityの質問です。

    ボタンを押すと、キャラクターの真後ろにオブジェクトが出現するようにしたいのですが、 using UnityEngine; using System.Collections; [ExecuteInEditMode()] public class GUIController : MonoBehaviour { public CharacterController characterController; public GameObject character; public GameObject domino; private Vector3 objPosition; // Use this for initialization void Start () { objPosition = new Vector3 (0, 0, 0); } void OnGUI(){ if(GUI.Button(new Rect(600, Screen.height - 160, 120, 120), "おす")){ Debug.Log("ぼたん"); float x = characterController.transform.localPosition.x; float y = characterController.transform.localPosition.y + 0.5f; float z = characterController.transform.localPosition.z - 0.64f; objPosition.Set(x, y, z); Debug.Log (x+","+y+","+z); GameObject domino_prefab = (GameObject)Instantiate(domino,objPosition, characterController.transform.rotation); } } } こうしてみたのですが、うまくキャラクターの真後ろにオブジェクトが出てきてくれません。 どなたか助けてください!

  • C#でエラーCS0165が出てしまいます。

    unityでC#スクリプトを書いています。 以下のことを書くと下から三行目の {int speed = speed + 1; }   でエラーCS0165が出てしまいます。 調べたのですが、よくわかりませんでした。 8行目に  int speed = 0; と書いているのですが、これでは割り当てられていないのでしょうか。文を修正していただければ幸いです。 using System.Collections; using System.Collections.Generic; using UnityEngine; public class a : MonoBehaviour { int speed = 0; void Start() { } void Update() { if (Input.GetKey(KeyCode.R)) {int speed = speed + 1; } } }

  • unityでのC++エラーの原因がわかりません!!

    最近unity2dで横スクロールアクションを勉強していて 今移動するなどのアニメーションを動かそうとしています しかし待機状態から移動するときのアニメーションに移行するスクリプトがうまくいきません 誰か教えてください error CS0411: The type arguments for method `UnityEngine.Component.GetComponent<T>()' cannot be inferred from the usage. Try specifying the type arguments explicitlyというエラーが出ます プログラムはこんな感じです using UnityEngine; using System.Collections; [RequireComponent(typeof(Rigidbody2D))] [RequireComponent(typeof(BoxCollider2D))] public class UnityChanController : MonoBehaviour { public Rigidbody2D cRigidbody2D { get { if(!_cRigidbody2D) _cRigidbody2D = rigidbody2D; return _cRigidbody2D; } } Rigidbody2D _cRigidbody2D; public Transform cTransform { get { if(!_cTransform) _cTransform = transform; return _cTransform; } } Transform _cTransform; public Animator cAnimator { get { if(!_cAnimator) _cAnimator = GetComponent(); return _cAnimator; } } Animator _cAnimator; public float moveSpeed = 5; public float jumpForce = 1000; float InputHorValue; bool isGrounded; bool canJump; void Update() { MecCheck(); InputCheck(); } void InputCheck() { InputHorValue = Input.GetAxisRaw("Horizontal"); if(isGrounded && Input.GetButtonDown("Jump")) canJump = true; } void MecCheck() { bool isRunning = InputHorValue != 0; cAnimator.SetBool("isRunning",isRunning); } void FixedUpdate() { Move(); Jump(); } void Move() { if((cTransform.localScale.x > 0 && InputHorValue < 0) || (cTransform.localScale.x < 0 && InputHorValue > 0)) { Vector2 temp = cTransform.localScale; temp.x *= -1; cTransform.localScale = temp; } cRigidbody2D.velocity = new Vector2(moveSpeed * InputHorValue, cRigidbody2D.velocity.y); } void Jump() { if(canJump) { canJump = false; isGrounded = false; cRigidbody2D.AddForce(Vector2.up * jumpForce); } } void OnCollisionEnter2D(Collision2D col) { if(col.gameObject.tag == "Ground") isGrounded = true; } }

  • キーボードで画像を動かす方法

    javaScriptで、 if (event.keyCode == 38) UP(); if (event.keyCode == 39) RIGHT(); if (event.keyCode == 37) LEFT(); if (event.keyCode == 40) DOWN(); のような処理で、上下左右の方向に画像などを移動させています。 しかし、上キーと右キーを同時に押しても 右上には移動しません。 率直にJavaScriptでキーボード入力を行って 右上、右下、左上、左下のように 2つのキーを同時に押したことを判定する方法は ありますでしょうか? ためしに&&を用いて 上キーと右キーが押されたとき用にUP_RIGHT() を作ってコールしたのですが思ったように動かないようでした。 どうかご教授ください。

  • Unity2DでX軸を瞬間移動したい。

    javascriptで作業をしています。 どう書けばいいのか分からず、拙いまとめ方ですがお願い致します。 クリック(タップ)で「GO」「BACK」のメッセージを出すスクリプトを其々当てたObjectを一回押すと、 X軸方向へ一定数(-方向と+方向)ポンっと瞬間移動っぽく移動し、 尚且つ、0値以降行かないようなスクリプトを書きたいのですが、 どのようにすれば良いでしょうか・・・・。 メッセージを出すスクリプトは以下です。 public var information : boolean = true; public var touch : boolean; public var target : GameObject; public var message : String; function Start() { touch = false; } function Update() { if (Input.GetMouseButtonDown(0)) { var tapPoint : Vector2 = Camera.main.ScreenToWorldPoint(Input.mousePosition); var collition2d : Collider2D = Physics2D.OverlapPoint(tapPoint); if (collition2d) { var hitObject : RaycastHit2D = Physics2D.Raycast(tapPoint,-Vector2.up); if (hitObject) { Debug.Log("Touch!" + hitObject.collider.gameObject.name); target.SendMessage( message, gameObject ); } } } } どうか宜しくお願い致します。

  • IEだけfloatがずれてしまう

    いつもお世話になります。 floatの書き方(IEの注意点?)について教えて頂きたいことがあります。 divで囲んだ文字列の右にボタンを配置していく、というのをfloatにて以下のように定義しました。 Firefox、Chromeでは一列に綺麗に並ぶのが確認できたのですが、IE8、9では、「abc」が右下にずれて しまい、正常に表示されませんでした。 --------------------- <html> <head> </head> <body> <div style="width: 200px; float: left; border: 1px black solid;"> あかさなた<label style="float: right;">abc</label> </div> <input type="button" value="ボタン1" style="float: left;" /> <input type="button" value="ボタン2" style="float: left;" /> </body> </html> --------------------- なぜIEだけこのような挙動になるのでしょうか。 あるいは、この書き方に何か間違いがあるのでしょうか。 宜しくお願いします。

    • ベストアンサー
    • CSS
  • unityで今プログラムを組んでいます

    今prefabで生成した物(クローン)のY座標を配列に入れて その中で現在一番数値の多いものを表示というものを作りたいのですが以下のプログラムだと 現在の高さではなくクリックで生成した物の高さになってしまいます。 理由が分からないのでアドバイスお願いします。 var test : Transform; var foo2 = new Array(); function Update(){     //クリック if (Input.GetButtonDown ("Fire1")) { Instantiate(test, transform.position, transform.rotation);//生成 } } //判定 function OnCollisionEnter(info : Collision) { foo2[i] = this.transform.position.y;//配列代入 //配列の中身調べる for(var A = 0; A <= i; A++){ if(foo2[i] > SavePos_y){ SavePos_y = foo2[i]; Debug.Log(foo2[i]); i++; } }

  • Ifを使う文章の書き方

    If~up, down, right, and left block are on. 上のような文章の場合、if とセットのカンマがどのカンマなのかを区別するように書くにはどうしたらいいのでしょうか。