//based on the input blocking type, returns a layer mask used in collision detection. public static LayerMask GetMaskFromBlockingType(BlockingType bType, bool includeActors = true) { int mask; switch (bType) { case BlockingType.walking: mask = Physics2D.GetLayerCollisionMask(LayerMask.NameToLayer("Walking")); if (includeActors == false) { mask = mask & ~GetActorMask(); } break; case BlockingType.flying: mask = Physics2D.GetLayerCollisionMask(LayerMask.NameToLayer("Flying")); if (includeActors == false) { mask = mask & ~GetActorMask(); } break; default: case BlockingType.ghost: mask = LayerMask.GetMask("Nothing"); break; } return(mask); }
void Start() { // Set filter flags on start. contactFilter.useTriggers = false; contactFilter.SetLayerMask(Physics2D.GetLayerCollisionMask(gameObject.layer)); contactFilter.useLayerMask = true; }
void OnEnable() { rb2d = GetComponent <Rigidbody2D>(); contactFilter.useTriggers = false; contactFilter.SetLayerMask(Physics2D.GetLayerCollisionMask(gameObject.layer)); contactFilter.useLayerMask = true; }
void Start() { this.facingDirection = this.initialFacingDirection; contactFilter.useTriggers = false; contactFilter.SetLayerMask(Physics2D.GetLayerCollisionMask(gameObject.layer)); contactFilter.useLayerMask = true; }
// Update is called once per frame void Update() { if (Input.GetMouseButtonDown(0)) { Vector2 world = Camera.main.ScreenToWorldPoint(Input.mousePosition); RaycastHit2D[] hits = new RaycastHit2D[10]; ContactFilter2D triggerCheck = new ContactFilter2D(); triggerCheck.SetLayerMask(Physics2D.GetLayerCollisionMask(gameObject.layer)); triggerCheck.useTriggers = true; Physics2D.Raycast(world, Vector2.zero, triggerCheck, hits); foreach (RaycastHit2D hit in hits) { if (hit && hit.collider.gameObject == gameObject) { if (menuActive) { menuActive = false; personalMenu.SetActive(false); } else { menuActive = true; personalMenu.SetActive(true); } } } } }
// Start is called before the first frame update void Start() { contactFilter.useTriggers = false; // Use the game object's layer as the collision mask layer contactFilter.SetLayerMask(Physics2D.GetLayerCollisionMask(gameObject.layer)); contactFilter.useLayerMask = true; }
IEnumerator KillPlayer() { // play death sound effect if (deathSFX) { PlaySound(deathSFX); } // freeze the player FreezeMotion(); turnUmbrellaOn = false; // play the death animation _animator.SetTrigger("_dead"); velocity.y = 4.0f; // let player doesn't collider with anyother objects in the scene this.gameObject.layer = _deadLayer; contactFilter.SetLayerMask(Physics2D.GetLayerCollisionMask(gameObject.layer)); // let death zone camera doesn't follow player anymore FindObjectOfType <DeadzoneCamera>().target = null; yield return(new WaitForSeconds(3f)); LevelManager.lm.LoadLevel("03a EndScene"); }
void Start() { // Set contact filer to only check raycast collisions on gameobjects contactFilter.useTriggers = false; contactFilter.SetLayerMask(Physics2D.GetLayerCollisionMask(gameObject.layer)); contactFilter.useLayerMask = true; }
void Start() { //A better way to use layers to sort objects in scene contactFilter.useTriggers = false; contactFilter.SetLayerMask(Physics2D.GetLayerCollisionMask(gameObject.layer)); contactFilter.useLayerMask = true; }
// Use this for initialization void Start() { Physics2D.SetLayerCollisionMask(8, Physics2D.GetLayerCollisionMask(8) & ~(1 << 8)); currentGeneration = 0; totalFailure = true; Initialize(); }
// Use this for initialization void Start() { particle = GetComponent <ParticleSystem>(); circleCollider = GetComponent <CircleCollider2D>(); Server_watcher.Singleton.onClientReady.Add(OnClientReady); if (!customFire) { ParticleSystem.EmissionModule particleEmit = particle.emission; ParticleSystem.ShapeModule particleShape = particle.shape; particleShape.radius = 1.5f * size / 64; particleEmit.rateOverTime = 250 * size / 64; circleCollider.radius = 1.25f * size / 64; } if (!isServer || thermal <= 0) { Destroy(circleCollider); } else if (Server_watcher.Singleton.local_player != null) { hitFilter = Physics2D.GetLayerCollisionMask(Server_watcher.Singleton.local_player.gameObject.layer); } }
void Start() { contactFilter.useTriggers = false; contactFilter.SetLayerMask(Physics2D.GetLayerCollisionMask(gameObject.layer)); contactFilter.useLayerMask = true; //OrientationVectors myOrientation = new OrientationVectors(Vector2.right, Vector2.down); }
// Start is called before the first frame update void Start() { contactFilter.useTriggers = false; contactFilter.SetLayerMask(Physics2D.GetLayerCollisionMask(gameObject.layer)); //check which collisions to detect contactFilter.useLayerMask = true; }
// Start is called before the first frame update void Start() { //Setting up the Contact Filter 2D. contactFilter.useTriggers = false; contactFilter.SetLayerMask(Physics2D.GetLayerCollisionMask(gameObject.layer)); contactFilter.useLayerMask = true; }
void OnCollisionEnter2D(Collision2D col) { //Debug.Log ("collide"); rb.velocity = new Vector2(0, 0); NotificationCenter.GetInstance().PostNotification("GameOver"); // 若撞柱而死,则旋转90度下落 if (col.collider.tag == "Tube") { Vector3 rotation = this.transform.localEulerAngles; this.transform.localEulerAngles = new Vector3(rotation.x, rotation.y, -90f); } this.enabled = false; Animator animator = GetComponent <Animator>(); animator.enabled = false; //BoxCollider2D collider = GetComponent<BoxCollider2D>(); //collider.enabled = false; int birdLayer = LayerMask.NameToLayer("Bird"); int layerMask = Physics2D.GetLayerCollisionMask(birdLayer); int tubeLayer = LayerMask.NameToLayer("Tube"); int maskChange = ~(1 << tubeLayer); Physics2D.SetLayerCollisionMask(birdLayer, layerMask & maskChange); }
void Start() { // Set up the contact filter for collisions ContactFilter.useTriggers = false; ContactFilter.SetLayerMask(Physics2D.GetLayerCollisionMask(gameObject.layer)); ContactFilter.useLayerMask = true; }
// Use this for initialization private void Start() { // contact filter layer setup contactFilter.useTriggers = false; contactFilter.SetLayerMask(Physics2D.GetLayerCollisionMask(gameObject.layer)); contactFilter.useLayerMask = true; }
void Start() { //initializing gameObjects/components anim = this.GetComponent <Animator>(); magic = this.GetComponent <Magic>(); contactFilter.useTriggers = false; contactFilter.SetLayerMask(Physics2D.GetLayerCollisionMask(gameObject.layer)); //determines which layers to check for collisions using the Pysics2D settings (layer collision matrix) contactFilter.useLayerMask = true; //initializing boolean flags isRight = true; isPushPull = false; isClimbingHor = false; isClimbingVer = false; canClimb = true; isHurt = false; //initialing other variables punchCount = 0; theScale = transform.localScale; //initializing the fist. fistCollider = fistObject.GetComponent <BoxCollider2D>(); fistCollider.enabled = false; }
private void Awake() { contactFilter.useTriggers = false; contactFilter.SetLayerMask(Physics2D.GetLayerCollisionMask(gameObject.layer)); contactFilter.useLayerMask = true; rigidBody2D = GetComponent <Rigidbody2D>(); }
// Start is called before the first frame update void Start() { contactFilter.useTriggers = false; // Check LayerMask collision matrix contactFilter.SetLayerMask(Physics2D.GetLayerCollisionMask(gameObject.layer)); contactFilter.useLayerMask = true; }
List <RaycastHit2D> hitList; //Filtered elements from the array get copied into the list // Use this for initialization void Start() { hitArray = new RaycastHit2D[maxCollisions]; hitList = new List <RaycastHit2D>(maxCollisions); colliderList = new List <ColliderContainer>(); #region add colliders to the list List <Collider2D> coll = new List <Collider2D>(); coll.AddRange(GetComponents <Collider2D>()); //Adds all colliders on the gameobject for (int i = 0; i < transform.childCount; i++) //Adds all colliders on child gameobjects { coll.AddRange(transform.GetChild(i).GetComponents <Collider2D>()); } coll.RemoveAll(t => t.isTrigger); //Removes triggers for (int i = 0; i < coll.Count; i++) //Adds the collider and the layer mask of it's gameobject { colliderList.Add(new ColliderContainer(coll[i], Physics2D.GetLayerCollisionMask(coll[i].gameObject.layer))); //Takes settings from the collision matrix in "Project Settings/Physics 2D" } #endregion contactFilter.useTriggers = false;//Set the filter to ignore triggers contactFilter.useLayerMask = true; }
IEnumerator Skill01() { //Questa coroutine gestisce l'uso dell'abilità dell'Intangibilità. //Per prima cosa disabilita l'uso ripetuto dell'abilità tramite la booleana "canUseSkill01". Poi setta la booleana isIntangible per //comunicare al gioco che il personaggio è adesso intangibile. Ciò serve agli oggetti per far partire i rispettivi script. canUseSkill01 = false; isIntangible = true; //anim.SetTrigger("Intangible"); //Cambia il layer del personaggio, alterando la sua capacità di collidere con determinati oggetti. Serve principalmente per entrare //negli oggetti designati. Dopodiché aspetta per la durata dell'abilità specificata nella variabile skill01_duration per far proseguire //lo script e terminare gli effetti dell'intangibilità. gameObject.layer = 9; contactFilter.SetLayerMask(Physics2D.GetLayerCollisionMask(gameObject.layer)); yield return(new WaitForSeconds(skill01_duration)); //Ripristina la normale capacità di collisione. gameObject.layer = 0; contactFilter.SetLayerMask(Physics2D.GetLayerCollisionMask(gameObject.layer)); //La booleana isStuck viene settata a vero dagli ostacoli quando il personaggio ci entra dentro, e viene messa a falso quando il personaggio esce. //Se il personaggio è ancora all'interno dell'ostacolo quando l'abilità termina, fa partire la funzione dello stordimento. if (isStuck) { StartCoroutine("Stun"); } //Disabilita la condizione di intangibilità, facendo tornare il personaggio nello stato normale e facendo partire il cooldown. isIntangible = false; StartCoroutine("Skill01Cooldown"); }
private void ManageInteraction() { if (Input.GetAxis("Jump") != 0) { if (!fireIsPressed) { print("fire"); fireIsPressed = true; ContactFilter2D contactFilter2DInteraction = new ContactFilter2D(); contactFilter2DInteraction.useTriggers = false; contactFilter2DInteraction.SetLayerMask(Physics2D.GetLayerCollisionMask(LayerMask.NameToLayer("Interaction"))); contactFilter2DInteraction.useLayerMask = true; RaycastHit2D[] interactionHit = new RaycastHit2D[16]; List <RaycastHit2D> hitBufferListInteraction = new List <RaycastHit2D>(16); hitBufferListInteraction.Clear(); int countInteraction = Physics2D.Raycast(gameObject.transform.position, Vector2.up, contactFilter2DInteraction, interactionHit); for (int i = 0; i < countInteraction; i++) { hitBufferListInteraction.Add(interactionHit[i]); } if (hitBufferListInteraction.Count > 0) { hitBufferListInteraction[0].transform.gameObject.GetComponent <Interaction>().Interact(); } } } else { fireIsPressed = false; } }
public void SpookCivilians() { int numColliders = 20; Collider2D[] colliders = new Collider2D[numColliders]; ContactFilter2D contactFilter = new ContactFilter2D(); contactFilter.layerMask = Physics2D.GetLayerCollisionMask(LayerMask.NameToLayer("AI")); contactFilter.useLayerMask = true; contactFilter.useTriggers = true; m_RoomCollider.OverlapCollider(contactFilter, colliders); GameObject player = GameObject.Find("Player"); int spookedCount = 0; foreach (Collider2D collided in colliders) { if (collided != null && collided.tag == "Civilian") { spookedCount++; collided.GetComponent <Civilian>().GetSpooked(); } } player.GetComponent <PlayerStats>().AddToSpookJuice(spookedCount * m_juicePerSpook); player.GetComponent <PlayerStats>().AddToScore(spookedCount * m_pointsPerSpook); }
void Start() { contactFilter.useTriggers = false; contactFilter.SetLayerMask(Physics2D.GetLayerCollisionMask(gameObject.layer)); //Debug.Log(gameObject.layer); contactFilter.useLayerMask = true; }
// Use this for initialization void Start() { stateManager = new PC2dStateManager(); stateManager.OnStateChange += Statechanged; rb2d = GetComponent <Rigidbody2D>(); //地面加速减速计算 groundAcceleration = groundSpeed / timeToGroundSpeed; groundDeceleration = (groundSpeed * groundSpeed) / (2 * groundStopDistance); //空中加速减速计算 airAcceleration = airSpeed / timeToAirSpeed; airDeceleration = (airSpeed * airSpeed) / (2 * airStopDistance); //起跳速度计算 v=sqrt(2gh) jumpStartSpeed = Mathf.Sqrt(2 * -1 * gravityModifier * Physics2D.gravity.y * jumpHeight); //按住跳跃键获得额外高度的时长,忽略重力 extraJumpTime = extraJumpHeight / jumpStartSpeed; //设置空中可跳跃次数 stateManager.airJumpMax = airJumpMax; //dash持续时间计算 dashDuration = dashDistance / dashSpeed; userInput.Reset(); contactFilter.SetLayerMask(Physics2D.GetLayerCollisionMask(gameObject.layer)); contactFilter.useLayerMask = true; }
private void Start() { //for collisions with other entities contactFilter.useTriggers = false; contactFilter.SetLayerMask(Physics2D.GetLayerCollisionMask(gameObject.layer)); contactFilter.useLayerMask = true; }
// Start is called before the first frame update void Start() { // change project settings -> physics 2d layer to update layer collisions contactFilter.useTriggers = false; contactFilter.SetLayerMask(Physics2D.GetLayerCollisionMask(gameObject.layer)); contactFilter.useLayerMask = true; }
void Start() { // not checking against Triggers contactFilter.useTriggers = false; // Use the usual Physics 2D layer collision matrix (Player Prefs -> Physics 2D) contactFilter.SetLayerMask(Physics2D.GetLayerCollisionMask(gameObject.layer)); }
protected virtual void Start() { maxVertMove = gravity * gravityModifier * Physics2D.gravity.magnitude; contactFilter.useTriggers = false; contactFilter.SetLayerMask(Physics2D.GetLayerCollisionMask(gameObject.layer)); contactFilter.useLayerMask = true; }