Hello, I am trying to import survival shooter demo project used in Unite 2014 but I don't know why with this Unity build physics doesn't work with this call: Code (CSharp): // Perform the raycast against gameobjects on the shootable layer and if it hits something... if(Physics.Raycast (shootRay, out shootHit, range, shootableMask)) { // Try and find an EnemyHealth script on the gameobject hit. EnemyHealth enemyHealth = shootHit.collider.GetComponent <EnemyHealth> (); // If the EnemyHealth component exist... if(enemyHealth != null) { // ... the enemy should take damage. enemyHealth.TakeDamage (damagePerShot, shootHit.point); } // Set the second position of the line renderer to the point the raycast hit. gunLine.SetPosition (1, shootHit.point); } I defined correctly shootable layer in all prefabs.
IIRC (but I might be mistaken) the Survival Shooter uses some Unity 4.5/4.6 features. And if that's the case the project needs to be altered to work with Unity 4.3. Does the project work as expected in the editor?
This project works with Unity 4.6 UI but I removed all the UI elements. If I play the project in Editor Mode doesn't works Physics.Raycast. I tried other Unity version and Physics.Raycast works fine
Yeah, so then it sounds like something in the project is broken the when running in Unity 4.3 (regardless of PSM).
If you set this script to the main camera and create a quad in front of the camera, with layer Default, console shows the print message. If you set the quad with the layer 9, console don't shows the message! (Note: console only shows the message if the quad uses layer Default. If I set layer to 1 or 2, console doesn't shows the message) Code (CSharp): using UnityEngine; using System.Collections; public class ExampleClass : MonoBehaviour { void Update() { Vector3 fwd = transform.TransformDirection(Vector3.forward); if (Physics.Raycast(transform.position, fwd, 10,9)) print("There is something in front of the object!"); } } I created a new project without any other script or model
I modified my script and now my source code is Code (CSharp): RaycastHit hit; if (Physics.Raycast(transform.position, fwd, out hit,100, layer)) { float distanceToGround = hit.distance; print ("distanceToGround " + distanceToGround + " layer " + hit.transform.gameObject.layer + " name " + hit.transform.gameObject.name); Debug.DrawLine(transform.position, hit.point); } It doesn't works fine. if I change my source to Code (CSharp): RaycastHit hit; if (Physics.Raycast(transform.position, fwd, out hit)) { float distanceToGround = hit.distance; print ("distanceToGround " + distanceToGround + " layer " + hit.transform.gameObject.layer + " name " + hit.transform.gameObject.name); Debug.DrawLine(transform.position, hit.point); } It shows correctly the layer number