Hot answers tagged

4

Rounding. If you attach the debugger and look at the values of your quaternion: You'll see that the values are just too small to be displayed with one tenth precision, as the debug value is displayed. You can confirm this by looking at: Debug.Log(LeftTurnLimit.eulerAngles); This will output the initial value you put in : 0.1, 0, 0 To address the ...


3

ally = (GameObject) ...is a syntax error. You need to comment this line just like you did the one below it. The problem is on that line, but because it's so malformed (no semicolon at the end), the compiler doesn't recognise it and assumes the problem is on the next line, transform.position = new Vector3(transform.position.x, transform.position.y - -5, ...


3

Let's take a closer look at what's actually happening here step by step. var sprite You create a new variable sprite which doesn't point to anything yet. sprite = image.sprite; And in the same line you point the variable to the same object as a different variable image.sprite is pointing to. sprite = obstacles[obstacleIndex].GetIcon(); Now you ...


2

This can be done with a very small modification to the script in the question Philipp linked: public class BlendFollower : MonoBehaviour { public Transform leader; public float followSharpness = 0.1f; Vector3 _followOffset; void Start() { // Cache the initial offset at time of load/spawn: _followOffset = ...


2

You can actually do one better. If it's the Test2 component you care about, then make that the type of the inspector variable you expose: private int bye = 1; public Test2 playerTestScript; void Start(){ playerTestScript.hello *= bye; Debug.Log(playerTestScript.hello); } This way you have absolutely no searching to do at runtime. Everything is ...


2

Find the normal between the two then scale that normal by the distance wanted. float distanceWanted = 3.0f; Vector3 diff = transform.position - player.position; diff.y = 0; // ignore Y transform.position = player.position + diff.normalized * distanceWanted;


2

You can do this with two cameras with different culling masks. When you have multiple cameras in your scene, each camera will be rendered separately. The culling mask decides what will be rendered by the camera. Then the output of all the cameras get drawn on top of each other in order of their "Depth" value. Click on "Layers -> Edit Layers" and create a ...


2

sprite is changed! But, that's not what you want. You want to change image.sprite. They are both different references to some Sprite. You're creating a second reference and then changing the second reference, rather than the reference image has. So just change image.sprite, not sprite.


2

It has to do with the way the coordinates systems are set. In particular, what it means to increment the Y coordinate for the mouse? an on the screen?. I'm not sure which convention Unity follows, but to put an example. The mouse coordinates might be (0,0) at the top-left corner and Y would increase when moving the mouse downward. On the other hand, the ...


2

The yield return new WaitForSeconds(time) construct only works in Coroutines. A coroutine must be started with the StartCoroutine(name) method and must itself be a method which returns an IEnumerator. So first you need to write your coroutine as a new method: IEnumerator FadeToNextLevel() { float fadetime = ...


2

When you write transform without anything in front of it, it refers to this.transform, ie. the transform attached to the GameObject this script instance is running on. It sounds like you instead want to modify the transform of the object hit by the raycast. To do this, we need to capture a reference to it... Ray ray = new Ray(transform.position, ...


1

Are you trying to use CompareTag on the gameObject that your RaycastHit is returning? If so it looks like you would need to do "hit.collider.gameObject.CompareTag". Or if that doesn't work, you would need to move that condition into a nested if statement. So: if (Input.GetMouseButton(0) && Physics.Raycast(ray, out hit, 10f) && ...


1

Rigidbody Contraints is a class to use for the rigidbody. In your case, instead of using hit.transform. = RigidbodyConstraints.FreezeRotation;, I would replace that with hit.GetComponent<Rigidbody>().constraints = RigidbodyConstraints.FreezeRotation;I see that you have tried to set a Rigidbody class on a Transform. Rigidbody constraints take a ...


1

I would advise using neither for this particular case. InvokeRepeating takes a method name, which means it's using reflection at runtime to look up the method to call. That's work we don't need to do, since we can already point the compiler at the exact method we want. Update executes every frame, but for spawning we typically want to leave some time (or ...


1

I hope this code I wrote helps you. If you have any more questions please ask. using UnityEngine; using UnityEngine.UI; public class NewBehaviourScript : MonoBehaviour { private AudioSource src; public Slider slider;// This is so we can drag the slider to the inspector view ot this script // Use this for initialization void Start () { ...


1

Animator.Play() works with the state in the Animator not the actual animation. I'm guessing you are not returning from the Flip-Forward state. Make sure to create a transition from to that state back to the default state and that the transition Has Exit Time property be ticked. This is a simple example of how the state machine should look. However I ...


1

use a mesh collider instead ! i just had the same problem. but then i just used a mesh collider instead of a sphere collider and the problem almost solved itself just be sure to update the mesh collider shared mesh as well: var meshInstance = Instantiate(meshes[type]); gameObject.GetComponent<MeshFilter> ().mesh = meshInstance; ...


1

After a bit of thought but no testing, it depends on your rockets. If the rockets are going to hit only the player then check on the script attached to the player and do everything there including destroying the rocket. If your rockets are going to hit more than the player then it's best to let the rockets do the collision checks on the rocket and have it ...


1

After some consideration I'm completely changing my previous answer. It would be more effective to implement a OnCollisionEnter method on the player that will do logic when a rocket hits him. That way less collision will have to be calculated and the physics engine will only have to keep track of the position of the rockets colliders and the rockets ...



Only top voted, non community-wiki answers of a minimum length are eligible