Пример #1
0
        void OnCollisionStay(Collision other)
        {
            if (other.collider.tag != "Paintable")
            {
                return;
            }
            PaintableObj obj = other.gameObject.GetComponent <PaintableObj> ( );
            RaycastHit   hit;

            if (Physics.Raycast(transform.position, (other.GetContact(0).point - transform.position).normalized, out hit, 1f))
            {
                int index = Weapon.GetRandomSplashTexIndex( );
                obj.Paint(hit.textureCoord, Weapon.SplashColor, Weapon.SplashTex[index], Weapon.SplashTexColors[index]);
                LeanPool.Despawn(this.gameObject);
            }
        }
Пример #2
0
        /// <summary>
        /// Overwrite this method to define how bullet detect PaintableObj
        /// </summary>
        /// <param name="props">props include everything bullet need</param>
        /// <param name="weapon">which weapon does this bullet belongs to</param>
        /// <typeparam name="T">type of props inherited from HitAttr</typeparam>
        override public void Fire <T> (T props, Weapon weapon)
        {
            this.Weapon = weapon;
            RayAttr rayProps = props as RayAttr;

            UpdateTrajectory(rayProps, weapon);
            RaycastHit hit;

            if (Physics.Raycast(rayProps.Pos, rayProps.Dir, out hit, rayProps.Dis))
            {
                if (hit.collider.gameObject.tag != "Paintable")
                {
                    return;
                }
                PaintableObj obj = hit.collider.GetComponent <PaintableObj> ( );
                if (obj)
                {
                    int index = Weapon.GetRandomSplashTexIndex( );
                    obj.Paint(hit.textureCoord, Weapon.SplashColor, Weapon.SplashTex[index], Weapon.SplashTexColors[index]);
                }
            }
            LeanPool.Despawn(this.gameObject);
        }