Hi guys. Can somebody help rewrite the code on C#? I need this check for my plugin teleportation.
Code:-- Create a local variable to store the BuildingBlock. local block = nil-- Create a Ray from the player to the ground to detect what the player is standing on local ray = new( UnityEngine.Ray._type, util.TableToArray { player.transform.position, UnityEngine.Vector3.get_down() } ) local arr = util.TableToArray { ray, new( UnityEngine.RaycastHit._type, nil ), 1.5, LayerMask } util.ConvertAndSetOnArray(arr, 2, 1.5, System.Int64._type) util.ConvertAndSetOnArray(arr, 3, LayerMask, System.Int32._type) if Raycast:Invoke( nil, arr ) then local hitEntity = global.RaycastHitEx.GetEntity(arr[1]) if hitEntity then if hitEntity:GetComponentInParent(global.BuildingBlock._type) then local buildingBlock = hitEntity:GetComponentInParent(global.BuildingBlock._type) if buildingBlock.name:find( "foundation", 1, true) then block = buildingBlock end end end end
Solved Code lua to c# (check teleport foundation)
Discussion in 'Rust Development' started by Sanlerus, Oct 20, 2015.
-
Like that:
Code:RaycastHit[] hits = UnityEngine.Physics.RaycastAll(player.transform.position, Vector3.down, 1.5f);foreach (RaycastHit hit in hits) { BuildingBlock block = hit.GetCollider().GetComponentInParent<BuildingBlock>(); if(block == null) continue; if(block.blockDefinition.hierachyName == "фундамент") // action }
Last edited by a moderator: Oct 20, 2015 -
My version:
Code:private BuildingBlock CheckFoundation(Vector3 position) { RaycastHit hit; if(!Physics.Raycast(position, Vector3.down, out hit, 0.1f, LayerMaskConstruction)) return null; BuildingBlock block = RaycastHitEx.GetEntity(hit) as BuildingBlock; if(block == null || !block.name.Contains("foundation")) return null; return block; }
Last edited by a moderator: Oct 20, 2015